def graphIt():
    areas = db_access.get_all_areas()
    placesList = []
    theAvgMeasurements = []

    for a in areas:
        placesList.append(a['name'])
        theAvg = db_utility.get_average_measurements_for_area(a['area_id'])
        if not theAvg:
            theAvg = 0
        theAvgMeasurements.append(theAvg)

    print(theAvgMeasurements)
    values = tuple(theAvgMeasurements)
    ind = na.array(range(len(values))) + 0.5
    width = 0.35
    plt.bar(ind, values, width, color='r')
    plt.ylabel('Average Measurement')
    plt.title('Areas')

    plt.xticks(ind + width / 2, tuple(placesList))
    plt.show()
예제 #2
0
 def testOneArea(self):
     areas = db_access.get_all_areas()
     k = filter_first(areas, lambda r: r[0] == 3)
     self.assertEqual('Kennesaw', k[1])
예제 #3
0
 def testNumberAreas(self):
     areas = db_access.get_all_areas()
     self.assertEqual(7, len(areas))
예제 #4
0
 def testOneArea(self):
     areas = db_access.get_all_areas()
     k = filter_first(areas, lambda r: r["area_id"] == 3)
     self.assertEqual("Kennesaw", k["name"])
#!/usr/bin/python

__author__ = 'KevinMortonMacPro'

import db_access
import db_utility
import KJM_HTML_Utility
import cgi
import cgitb
cgitb.enable()

areas = db_access.get_all_areas()

def printErrorMSG(formV):
	theMsg =""
	
	if isinstance(formV, list):
		errorMSG  = ''' 
		You may only select a single value.
		<br><p>Form data received:\t{}</p>'''.format(formV)
		
	elif formV.isdigit():
		errorMSG  = ''' 
		The location ID doesn't match any locations in the database.
		<br><p>Form data received:\t{}</p>'''.format(formV)
	
	elif formV == 'None':
		errorMSG = ''' 
			No data was received. 
			<br><p>Form data received:\t{}
			</p>'''.format(formV)
예제 #6
0
 def testNumberAreas(self):
     areas = db_access.get_all_areas()
     self.assertEqual(7, len(areas))
예제 #7
0
def area():
    response.content_type = "application/json"
    data = get_all_areas()
    return dumps(data)
예제 #8
0
            </div>""")

bool = True
# numeric = int(user_val)
if user_val != None:
    for abc in user_val:
        if abc.isdigit() == False:
            bool = False
            # print(abc)

# if user_val != None and type(user_val) != int:
if user_val != None and bool:
    val = get_area_by_id(user_val)

    if val == None: #lines 44-49 will detect if a user has submitted a value which can't be found within the database
        a = get_all_areas()
        print("<div id=\"error_page1\"><strong>ERROR: User entered an ID which was not found!</strong></br>Select an Area</br><form method=\"get\" action=\"/cgi-bin/location_table.py\"><select name=\"area_id\" size=\"5\"></div>")
        for x in a:
            print("<option value=\"" + str(x['area_id']) + "\">" + x['name'] + "</option>")
        print("</select></br><input id=\"sButton\" type=\"submit\" value=\"Submit\"></form></div></div></body></html>")

    else:
        # print("test", val)
        for a in val:
            print("<div id=\"page_body2\">Location Information for the " + a['name'] + " area </br></br>")
        print("<form method =\"get\" action=\"/cgi-bin/measurement_table.py\"><table class=\"grid\"><th class=\"grid\">Select</th><th class=\"grid\">ID</th><th class=\"grid\">Name</th><th class=\"grid\">Altitude</th>")
        for x in get_locations_for_area(user_val):
            # print("<tr> <td><input type=\"radio\" value=\"" + x['name'] + "\" name=\"" + x['name'] + "\"></td> <td>" + str(x['location_id']) + " </td> <td>" + x['name'] + " </td> <td>" + str(x['altitude']) + " </td> </tr>")
            print("<tr> <td><input type=\"radio\" value=\"" + str(x['location_id']) + "\" name=\"location_id\"></td> <td>" + str(x['location_id']) + " </td> <td>" + x['name'] + " </td> <td>" + str(x['altitude']) + " </td> </tr>")

        print("</table></br><input id=\"sButton\" type=\"submit\"></form></div></body></html>")
예제 #9
0
# Chart formatting
space = 18
line_format = ' {:>4}   {:<25}   {:<10}  {:^12}  {:' + str(space + 1) + '} '
divider_line1 = '-' * (84)
divider_line3 = '-' * 82
line_format2 = ' {:^' + str(60 + space) + '} '

# Print Chart
# Print header
print("\n" + divider_line1)
print(divider_line1)
print(line_format.format("ID", "Name", "Num Loc", "Avg Value", "Categories"))
print(divider_line3)

# Print information
for i in db_access.get_all_areas():
    avg = db_utility.get_average_measurements_for_area(
        i[0])  # Calculate average
    print(
        line_format.format(
            str(i[0]),
            i[1],
            str(db_utility.number_of_locations_by_area(
                i[0])),  # areaId, name, num of locations
            "-----" if avg is None else str(round(
                avg, 2)),  # avg measurement, round 2 decimals
            str(", ".join(
                str(j[1]) for j in db_access.get_categories_for_area(
                    i[0])))))  # categories
def area():
    area = get_all_areas()
    response.content_type = "application/json"
    return dumps(area)
예제 #11
0
import db_access
import db_utility

categories = ''
my_tuple_report = []
my_tuple = db_access.get_all_areas()
template = "{:>3}  {:<25}  {:>10}  {:>25}     {:<30}"
line = template.format('ID', 'Name', "Num Loc", "Avg Value", 'Categories')
print(line)
for area_row in my_tuple:
    #print(area_row)
    categories = ''
    area_id = area_row[0]
    area_name = area_row[1]
    loc_num = db_utility.number_of_locations_by_area(area_id)
    avg_value = db_utility.get_average_measurements_for_area(area_id)
    if avg_value is None:
        avg_value = "        _________________"
    my_categories = db_access.get_categories_for_area(area_id)
    #print(my_categories)
    for category_row in my_categories:
        categories = categories + category_row + ', '
    if categories is None:
        pass
    else:
        categories = categories.rstrip(', ')
    template = "{:3}  {:25}  {:10}  {:25.4}     {:30}"
    line2 = template.format(area_id, area_name, loc_num, avg_value, categories)
    print(line2)