Blame view

Database/adjacent_area.py 859 Bytes
16f90fbc   Eduardo Eloy   database and impl...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import csv, re, sqlite3

fin = open("ii.csv", "rt")

con = sqlite3.connect("database2.db")
cur = con.cursor()

first_line = fin.readline()
s = first_line.split(",")
current = s[0]
cur.execute("SELECT area FROM area where ug like "+current) 
result = cur.fetchone() 
area = float(result[0])
totarea = area
for line in fin:
	s = line.split(",")
	if(s[0] == current):
		totarea = totarea + float(s[2]) - area
	else: 
		print(str(current)+","+str(totarea))
		if(str(s[1]) == "-1"):
			current = s[0]
			cur.execute("SELECT area FROM area where ug like "+current) 
			result = cur.fetchone() 
			area = float(result[0])
			totarea = area
		else:
			current = s[0]
			cur.execute("SELECT area FROM area where ug like "+current) 
			result = cur.fetchone() 
			area = float(result[0])
			totarea = float(s[2]) 
			
print(str(current)+","+str(totarea))

fin.close()