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","methods_id") VALUES'
20
methodsInsertBeg = 'INSERT INTO v_methods ("entryInfo_id") VALUES'
21
methodInsertBeg = 'INSERT INTO v_methodtype ("entryInfo_id","methods_id_id","attr_id","attr_system","attr_scope","name") 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
maxProtocolsSQL = 'select max(id) from v_methods'
30
psqlcur.execute(maxProtocolsSQL)
31
maxProtocols = psqlcur.fetchone()[0]
32
if maxProtocols == None:
33
  maxProtocols = 0
34

    
35
methodIds = ['BIEN2_0.1 ha  transect, stems >= 2.5 c','BIEN2_1 ha, stems >= 10 cm dbh: indivi','BIEN2_0.01 ha, stems >= 10 cm dbh; 16','BIEN2_Point-intercept: species (line-i','BIEN2_1 ha permanent plot, >=10cm dbh','BIEN2_0.1 ha Gentry transect, >=2.5 cm']
36
methodNames = ['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
psi = methodsInsertBeg
42
pi = methodInsertBeg
43

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

    
61
psqlconn.rollback()
62

    
(12-12/21)