diff --git a/gracedb/datas.py b/gracedb/datas.py deleted file mode 100644 index 32cbcbad5f8df4a9a5361f80c1bc678cfa175345..0000000000000000000000000000000000000000 --- a/gracedb/datas.py +++ /dev/null @@ -1,154 +0,0 @@ -from django.http import HttpResponse -from django.template import RequestContext -from django.shortcuts import render_to_response - -from gracedb.gracedb.models import Event - -from django.db import connection, transaction - -import gviz_api -from datetime import datetime - -def index(request): - - # foo = Event.objects.raw("select date_format(date, '%Y-%m') as month, sum(quantity) as hours from hourentries group by date_format(date, '%Y-%m') order by date;") - -# q = "SELECT * from gracedb_event LIMIT 10" -# q = "SELECT date_format(created, '%%Y-%%m') as month, COUNT(*) AS total FROM gracedb_event GROUP BY date_format(created, '%%Y-%%m') order by created" - -# cursor = connection.cursor() -# cursor.execute(q) - -# desc = cursor.description -# foo = [ dict(zip([col[0] for col in desc], row)) -# for row in cursor.fetchall() -# ] - foo = "I AM THE FOO" - - return render_to_response( - 'gracedb/datas.html', - {'thing' : str(foo)}, - context_instance=RequestContext(request)) - -def source(request): - tq = request.GET.get('tq',"") - tqx = request.GET.get('tqx',"") - - atypes = ["OM", "LM"] - atypes = [shortname for (shortname, _) in Event.ANALYSIS_TYPE_CHOICES] - - description = [ ("Year", "string"), ] - - buffy = [] - - things = dict(zip(atypes, [{}]*len(atypes))) - things = {} - dates = set() - for t in atypes: - description.append( (t, "number") ) - q = "SELECT date_format(created, '%%Y-%%m') as month, COUNT(*) AS total FROM gracedb_event WHERE analysisType = %s GROUP BY date_format(created, '%%Y-%%m')" - cursor = connection.cursor() - cursor.execute(q, [t]) - d = {} - for row in cursor.fetchall(): - n = int(row[1]) - d[str(row[0])] = n - dates.update([row[0]]) - buffy.append(row) - things[t] = d - cursor.close() -# THINGS -# {'OM': {u'2010-01': 37, u'2011-08': 1, u'2010-08': 5193, u'2010-07': 1085, u'2011-11': 1, u'2010-04': 433, u'2011-12': 3, u'2009-07': 10, u'2009-06': 5, u'2010-03': 528, u'2010-02': 307, u'2009-10': 109, u'2009-11': 281, u'2009-12': 1, u'2010-06': 221, u'2010-09': 4018, u'2010-05': 519, u'2012-01': 3, u'2010-10': 1871, u'2009-08': 149}, 'LM': {u'2010-01': 37, u'2011-08': 1, u'2010-08': 5193, u'2010-07': 1085, u'2011-11': 1, u'2010-04': 433, u'2011-12': 3, u'2009-07': 10, u'2009-06': 5, u'2010-03': 528, u'2010-02': 307, u'2009-10': 109, u'2009-11': 281, u'2009-12': 1, u'2010-06': 221, u'2010-09': 4018, u'2010-05': 519, u'2012-01': 3, u'2010-10': 1871, u'2009-08': 149}} - -# BUFFY -# [(u'2009-06', 1L), (u'2009-07', 69L), (u'2009-08', 149L), (u'2009-10', 109L), (u'2009-11', 281L), (u'2009-12', 243L), (u'2010-01', 37L), (u'2010-02', 307L), (u'2010-03', 528L), (u'2010-04', 433L), (u'2010-05', 519L), (u'2010-06', 221L), (u'2010-07', 262L), (u'2010-08', 902L), (u'2010-09', 962L), (u'2010-10', 318L), (u'2011-11', 4L), (u'2009-06', 5L), (u'2009-07', 10L), (u'2009-12', 1L), (u'2010-07', 1085L), (u'2010-08', 5193L), (u'2010-09', 4018L), (u'2010-10', 1871L), (u'2011-08', 1L), (u'2011-11', 1L), (u'2011-12', 3L), (u'2012-01', 3L)] - - data_table = gviz_api.DataTable(description) - - data = [ - ["2011-01", 33, 44], - ["2011-02", 43, 24], - ["2011-03", 38, 34], - ] - - dates = list(dates) - dates.sort() - - data = [] - for date in dates: - row = [date] - for t in atypes: - try: - row.append(things[t][date]) - except: - row.append(0) - data.append(row) - - data_table.LoadData(data) - #return HttpResponse(str(dates)) - #return HttpResponse(str(data)) - return HttpResponse(data_table.ToResponse(tqx=tqx)) - -def sourcea(request): - -# description = [ -# ("year", "string", "year"), -# ("first", "number", "first"), -# ("second", "number", "second"), -# ] -# data_table = gviz_api.DataTable(description) -# data_table.LoadData([ -# [2001, 1,3], -# [2002, 2,4], -# [2003, 3,5], -# ]) -# return HttpResponse(data_table.ToResponse(columns_order=("year", "first", "second"))) - - tq = request.GET.get('tq',"") - tqx = request.GET.get('tqx',"") - - description = { - "month": ("date", "Month"), - "type": ("string", "Type"), - "total": ("number", "Total Events"), - } - data_table = gviz_api.DataTable(description) - - q = "SELECT date_format(created, '%%Y-%%m') as month, analysisType, COUNT(*) AS total FROM gracedb_event GROUP BY date_format(created, '%%Y-%%m'),analysisType order by created" - - cursor = connection.cursor() - cursor.execute(q) - - def blarg(d): - year, month = d.split('-') - return datetime(int(year), int(month), 1) - -# for row in cursor.fetchall(): -# data_table.addRow([blarg(row[0]), row[1], row[2]]) - data = [ - #{ "month": row[0], "total": row[1] } for row in cursor.fetchall() - { "month": blarg(row[0]), "type": row[1], "total": row[2] } for row in cursor.fetchall() - ] - data_table.LoadData(data) - - return HttpResponse(data_table.ToResponse(columns_order=("month", "type", "total"), tqx=tqx)) - return HttpResponse(data_table.ToResponse(tqx=tqx)) - -def sourcex(request): - - description = {"name": ("string", "Name"), - "salary": ("number", "Salary"), - "full_time": ("boolean", "Full Time Employee")} - data = [{"name": "Mike", "salary": (10000, "$10,000"), "full_time": True}, - {"name": "Jim", "salary": (800, "$800"), "full_time": False}, - {"name": "Alice", "salary": (12500, "$12,500"), "full_time": True}, - {"name": "Bob", "salary": (7000, "$7,000"), "full_time": True}] - - data_table = gviz_api.DataTable(description) - data_table.LoadData(data) - #print "Content-type: text/plain" - #print - #print data_table.ToJSonResponse(columns_order=("name", "salary", "full_time"), - # order_by="salary") - return HttpResponse(data_table.ToResponse(columns_order=("name", "salary", "full_time"), order_by="salary", tqx=tqx)) - diff --git a/templates/gracedb/datas.html b/templates/gracedb/datas.html deleted file mode 100644 index 9e05c51e9f99ecb330ad8bd16108bd7d6a8cd0fb..0000000000000000000000000000000000000000 --- a/templates/gracedb/datas.html +++ /dev/null @@ -1,187 +0,0 @@ -{% extends "base.html" %} - -{% block jscript %} -<script type="text/javascript" src="https://www.google.com/jsapi"></script> - <script type="text/javascript"> - // Load the Visualization API and the piechart package. - google.load('visualization', '1.0', {'packages':['corechart','controls']}); - </script> - - - <script type="text/javascript"> - google.setOnLoadCallback(setupDash); - function setupDash() { - var dashboard = new google.visualization.Dashboard( - document.getElementById('dash')); - - var chart = new google.visualization.ChartWrapper({ - 'chartType': 'ColumnChart', - 'containerId': 'chart', - 'options': { - 'width': 800, - 'height': 300, - } - }); - - var control = new google.visualization.ControlWrapper({ - 'controlType': 'CategoryFilter', - 'containerId': 'control', - 'options': { - 'filterColumnLabel': 'Year', - }, - //'state': {}, - }); - - dashboard.bind(control, chart); - getData(dashboard); - } - function getData(dashboard) { - var opts = {sendMethod: 'xhr'}; - var query = new google.visualization.Query('https://moe.phys.uwm.edu/gracedb/datas/source', opts); - query.send(function(response){ - if (response.isError()) { - alert("ERRORZ"); - return; - } - data = response.getDataTable(); - dashboard.draw(data); - }); - } - </script> - - - <script type="text/javascript"> - google.setOnLoadCallback(initialize); - function fakeData() { - var data = new google.visualization.DataTable(); - data.addColumn('string', 'Year'); - data.addColumn('number', 'Sales'); - data.addColumn('number', 'Expenses'); - data.addRows([ - ['2004', 1000, 400], - ['2005', 1170, 460], - ['2006', 660, 1120], - ['2007', 1030, 540] - ]); - return data; - } - - function initialize() { - // Replace the data source URL on next line with your data source URL. - // Specify that we want to use the XmlHttpRequest object to make the query. - var opts = {sendMethod: 'xhr'}; - var query = new google.visualization.Query('https://moe.phys.uwm.edu/gracedb/datas/source', opts); - - // Optional request to return only column C and the sum of column B, grouped by C members. - //query.setQuery('select C, sum(B) group by C'); - - // Send the query with a callback function. - query.send(handleQueryResponse); - }; - - function handleQueryResponse(response) { - if (response.isError()) { - alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); - return; - } - - - var data = response.getDataTable(); - var chart = new google.visualization.ColumnChart(document.getElementById('chart_div2')); - var options = { - width: 800, - height: 240, - //is3D: true, - hAxis: { title: "year", strictFirstColumnType: true } - }; - chart.draw(data, options); - //chart.draw(fakeData(), options); - } - </script> - - <script type="text/javascript"> - // Set a callback to run when the Google Visualization API is loaded. - google.setOnLoadCallback(drawDashboard); - - // Callback that creates and populates a data table, - // instantiates a dashboard, a range slider and a pie chart, - // passes in the data and draws it. - function drawDashboard() { - - // Create our data table. - var data = google.visualization.arrayToDataTable([ - ['Name', 'Donuts eaten', 'thrown up'], - ['Michael' , 5,6], - ['Elisa', 7,8], - ['Robert', 3,4], - ['John', 2,3], - ['Jessica', 6,5], - ['Aaron', 1,0], - ['Margareth', 8,7] - ]); - - // Create a dashboard. - var dashboard = new google.visualization.Dashboard( - document.getElementById('dashboard_div')); - - // Create a range slider, passing some options - var donutRangeSlider = new google.visualization.ControlWrapper({ - 'controlType': 'NumberRangeFilter', - 'containerId': 'filter_div', - 'options': { - 'filterColumnLabel': 'Donuts eaten' - } - }); - - // Create a pie chart, passing some options - var pieChart = new google.visualization.ChartWrapper({ - 'chartType': 'BarChart', - 'containerId': 'chart_div', - 'options': { - 'width': 300, - 'height': 300, - 'pieSliceText': 'value', - 'legend': 'right' - } - }); - - // Establish dependencies, declaring that 'filter' drives 'pieChart', - // so that the pie chart will only display entries that are let through - // given the chosen slider range. - dashboard.bind(donutRangeSlider, pieChart); - - // Draw the dashboard. - dashboard.draw(data); - } - </script> - -{% endblock %} - -{% block title %}¡¡DATAS!!{% endblock %} -{% block heading %}¡¡DATAS!!{% endblock %} -{% block pageid %}datas{% endblock %} - - -{% block content %} - -IMA dATAhATE-Ahhhhhhhhhhhh -{{ thing }} -<hr/> -<div id="chart_div1">ONEs</div> -<hr/> -<div id="chart_div2">Goobs</div> - -<div id="dash"> - Dashle - <div id="chart">Chartle</div> - <div id="control">controlle</div> -</div> - - <!--Div that will hold the dashboard--> - <div id="dashboard_div"> - <!--Divs that will hold each control and chart--> - <div id="chart_div"></div> - <div id="filter_div"></div> - </div> - -{% endblock %} diff --git a/urls.py b/urls.py index aaaf7d3abe50ef6fc6a528c03c9f7dbe260281cd..9d2d04ede91e9c537502d343a1dd9bfe09874a1b 100644 --- a/urls.py +++ b/urls.py @@ -31,9 +31,6 @@ urlpatterns = patterns('', (r'^reports/(?P<path>.+)$', 'django.views.static.serve', {'document_root': settings.LATENCY_REPORT_DEST_DIR}), - url(r'^datas/$', 'gracedb.gracedb.datas.index', name="datas"), - url(r'^datas/source$', 'gracedb.gracedb.datas.source', name="source"), - # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')),