Project

General

Profile

1
import psycopg2
2
import MySQLdb
3
import datetime
4
from xml.dom import minidom
5
from xml.dom.minidom import getDOMImplementation
6
from bien.v.models import *
7

    
8
mysqldb = MySQLdb.connect(host="localhost", user="admin", passwd="lae5eiNa",db="bien2")
9
mysqlcursor = mysqldb.cursor()
10

    
11
psqlconn = psycopg2.connect("dbname=bien_test user=bien_dba password=bien")
12
psqlconn.set_client_encoding('LATIN1')
13
psqlcur = psqlconn.cursor()
14

    
15
system = "BIEN2"
16
scope = "system"
17

    
18
entryInfoInsertBeginning = 'INSERT INTO v_entryinfo ("creationDate","lastUpdatedDate","dataSource") VALUES'
19
vegXInsertBeginning = 'INSERT INTO v_vegx ("entryInfo_id","strata_id") VALUES'
20
strataInsertBeg = 'INSERT INTO v_strata ("entryInfo_id") VALUES'
21
stratumInsertBeg = 'INSERT INTO v_stratumtype ("entryInfo_id","strata_id_id","attr_id","attr_system","attr_scope","stratumName") VALUES'
22

    
23
batchSize = 500
24

    
25
maxEISql = 'select max(id) from v_entryinfo'
26
psqlcur.execute(maxEISql)
27
maxEntryInfo = psqlcur.fetchone()[0]
28

    
29
maxStrataSQL = 'select max(id) from v_strata'
30
psqlcur.execute(maxStrataSQL)
31
maxStrata = psqlcur.fetchone()[0]
32
if maxStrata == None:
33
  maxStrata = 0
34

    
35
stratumIds = ['BIEN2_TotalIndividuals','BIEN2_TotalIndividualsAbove1cm','BIEN2_TotalIndividualsAbove2.5cm','BIEN2_TotalIndividualsAbove10cm','BIEN2_PercentCover']
36
stratumNames = ['All individuals in plot','Greater than or equal to 1 cm dbh','Greater than or equal to 2.5 cm dbh','Greater than or equal to 10 cm dbh','Percent cover']
37

    
38

    
39
eii = entryInfoInsertBeginning
40
vxi = vegXInsertBeginning
41
ssi = strataInsertBeg
42
si = stratumInsertBeg
43

    
44
iterCt = 0
45
for stratumId in stratumIds:
46
  iterCt = iterCt + 1
47
  eii = eii + "('" + datetime.date.today().strftime("%Y-%m-%d") + "','" + datetime.date.today().strftime("%Y-%m-%d") + "','BIEN2'), "
48
  ssi = ssi + '(' + str(maxEntryInfo + iterCt) + '), '
49
  vxi = vxi + '(' + str(maxEntryInfo + iterCt) + ',' + str(maxStrata + iterCt) + '), '
50
  si = si + '(' + str(maxEntryInfo + iterCt) + ',' + str(maxStrata + iterCt) + ",'" + stratumId + "','" + system + "','" + scope + "','" + stratumNames[iterCt-1] + "'), "
51
  if iterCt % batchSize == 0 or iterCt == len(stratumIds):
52
    psqlcur.execute(eii[:(len(eii)-2)])
53
    psqlconn.commit()
54
    psqlcur.execute(ssi[:(len(ssi)-2)])
55
    psqlconn.commit()
56
    psqlcur.execute(vxi[:(len(vxi)-2)])
57
    psqlconn.commit()
58
    psqlcur.execute(si[:(len(si)-2)])
59
    psqlconn.commit()
60

    
61
psqlconn.rollback()
62

    
(13-13/21)