-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_utility.py
50 lines (40 loc) · 1.06 KB
/
db_utility.py
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
37
38
39
40
41
42
43
44
45
46
47
48
__name__ = 'db_utility.py'
__author__ = 'Max W. Nakel'
import math
import sqlite3
from db_access import get_measurements_for_location, get_locations_for_area
conn = sqlite3.connect("measures.sqlite")
from db_access import get_all_areas
def get_average_measurements_for_area(area_id):
rVal = 0
id = get_locations_for_area(area_id)
if not id:
return None
lst = []
for z in id:
lst.append(z['location_id'])
if not lst:
return None
summe = []
three = []
for r in lst:
summe = (get_measurements_for_location(r))
if summe:
three += (summe)
sum = 0
total = len(three)
for e in three:
sum += e['value']
rVal = sum/total
return rVal
"""
Returns the average value of all measurements for all locations in the given area.
Returns None if there are no measurements.
"""
def number_of_locations_by_area(area_id):
id = get_locations_for_area(area_id)
num = len(id)
return num
"""
Returns the number of locations for the given area.
"""