<commit_before>from flask import Blueprint, render_template, request, url_for, redirect
from app import db, login_manager, pubnub
from flask.ext.login import login_required, current_user
import datetime

mod_grows = Blueprint('grows', __name__)

@mod_grows.route('/grows/<current_grow>', methods=['GET'])
@login_required
def list_grow(current_grow):
    count = 0
    data = {'pH':[], 'lux': [], 'EC':[], 'TDS':[], 'PS':[], 'PS':[], 'humidity':[], 'airTemp':[], 'waterTemp':[]}
    user_devices = []
    user_grows = []
    device_list = []
    grows_list = []
    assoc_device_name = ''
    username = current_user.get_id()
    grows = db.grows.find({'grow_name' : current_grow})
    for grow in grows:
        assoc_device_name = grow['device_name']
        experiment = grow['experiment']
        grows_list.append((current_grow, grow['device_name'], grow['sensors'], grow['actuators'], grow['controls'], grow['plant_profile']))
    data_points = db.data.find({'grow_name' : current_grow}).sort('_id',-1).limit(151200)
    for data_point in data_points:
        if count%3600 == 0:
            data['pH'].append(data_point['pH'])
            data['lux'].append(data_point['lux'])
            data['EC'].append(data_point['EC'])
            data['TDS'].append(data_point['TDS'])
            data['PS'].append(data_point['PS'])
            data['humidity'].append(data_point['humidity'])
            data['airTemp'].append(data_point['airTemp'])
            data['waterTemp'].append(data_point['waterTemp'])
        count+=1
    print data
    if assoc_device_name == "":
        device_list.append(("No Device Linked", "No Device Linked", [] ,{}, "", ""))
    else:
        devices = db.devices.find({'device_name': assoc_device_name })
        for device in devices:
            device_list.append((device['device_name'], device['type'], \
                    device['sensors'], device['actuators'], device['kit'], device['device_id']))

    devices = db.devices.find({'username': current_user.get_id()})
    for device in devices:
        user_devices.append((device['device_name'], device['type'], \
                device['sensors'], device['actuators'], device['kit'], device['device_id']))
    grows = db.grows.find({'username' : current_user.get_id()})
    for grow in grows:
        user_grows.append((grow['grow_name'], grow['device_name'], grow['sensors'], grow['actuators'], grow['controls']))
    
    return render_template('grows/grows.html',
                            username=username, current_grow=current_grow, experiment=experiment, current_device=assoc_device_name, \
                           device=device_list, grow=grows_list, my_devices=user_devices, my_grows=user_grows, data=data)

@mod_grows.route('/link/<current_grow>/<link_device>', methods=['POST'])
@login_required
def link(current_grow, link_device):
    devices = db.devices.find({'device_name':link_device})
    for device in devices:
        device_id = device['device_id']
    result = db.grows.update_one(
      { "grow_name" : current_grow},
      {
      '$set': {'device_name' : link_device, 'device_id' : device_id, 'sensors': [], 'actuators' : {}, 'controls' : {"time":[], "condition" :[]} }
      },
      upsert=True
      )
    return redirect(url_for('grows.list_grow', current_grow=current_grow))

@mod_grows.route('/edit_grows/<current_grow>', methods=['POST'])
@login_required
def edit_grow(current_grow):
    grows = db.grows.find({'grow_name':current_grow})
    for grow in grows:
        device_id = grow['device_id']
    devices = db.devices.find({'device_id':device_id})
    for device in devices:<commit_msg>Data for the graphs on the grow page<commit_after>from flask import Blueprint, render_template, request, url_for, redirect
from app import db, login_manager, pubnub
from flask.ext.login import login_required, current_user
import datetime

mod_grows = Blueprint('grows', __name__)

@mod_grows.route('/grows/<current_grow>', methods=['GET'])
@login_required
def list_grow(current_grow):
    count = 0
    pHchartData = []
    ecChartData = [];
    luxChartData = [];
    tempChartData = [];
    humidityChartData = [];

    # data = {'pH':[], 'lux': [], 'EC':[], 'TDS':[], 'PS':[], 'PS':[], 'humidity':[], 'airTemp':[], 'waterTemp':[]}
    user_devices = []
    user_grows = []
    device_list = []
    grows_list = []
    assoc_device_name = ''
    username = current_user.get_id()
    grows = db.grows.find({'grow_name' : current_grow})
    for grow in grows:
        assoc_device_name = grow['device_name']
        experiment = grow['experiment']
        grows_list.append((current_grow, grow['device_name'], grow['sensors'], grow['actuators'], grow['controls'], grow['plant_profile']))
    data_points = db.data.find({'grow_name' : current_grow}).sort('_id',-1).limit(151200)
    for data_point in data_points:
        if count%3600 == 0:
            date = datetime.datetime(year=data_point['year'], month=data_point['month'], day=data_point['day'], \
                                hour=data_point['hour'], minute=data_point['min'], second=data_point['sec'])
            pHchartData.append({"date" : date, "value" : data_point['pH']})
            ecChartData.append({"date" : date, "ec_value" : data_point['EC'], "tds" : data_point['TDS'], "ps":data_point['PS']})
            luxChartData.append({"date" : date, "value" : data_point['lux']})
            tempChartData.append({"date" : date, "waterTemp" : data_point['waterTemp'], "airTemp": data_point['airTemp']})
            humidityChartData.append({"date" : date, "value" : data_point['humidity']})
        count+=1
    
    # print pHchartData, ecChartData, luxChartData, tempChartData, humidityChartData
    if assoc_device_name == "":
        device_list.append(("No Device Linked", "No Device Linked", [] ,{}, "", ""))
    else:
        devices = db.devices.find({'device_name': assoc_device_name })
        for device in devices:
            device_list.append((device['device_name'], device['type'], \
                    device['sensors'], device['actuators'], device['kit'], device['device_id']))

    devices = db.devices.find({'username': current_user.get_id()})
    for device in devices:
        user_devices.append((device['device_name'], device['type'], \
                device['sensors'], device['actuators'], device['kit'], device['device_id']))
    grows = db.grows.find({'username' : current_user.get_id()})
    for grow in grows:
        user_grows.append((grow['grow_name'], grow['device_name'], grow['sensors'], grow['actuators'], grow['controls']))
    
    return render_template('grows/grows.html',
                            username=username, current_grow=current_grow, experiment=experiment, current_device=assoc_device_name, \
                           device=device_list, grow=grows_list, my_devices=user_devices, my_grows=user_grows, pHchartData=pHchartData,\
                           ecChartData=ecChartData, luxChartData=luxChartData, tempChartData=tempChartData, humidityChartData=humidityChartData)

@mod_grows.route('/link/<current_grow>/<link_device>', methods=['POST'])
@login_required
def link(current_grow, link_device):
    devices = db.devices.find({'device_name':link_device})
    for device in devices:
        device_id = device['device_id']
    result = db.grows.update_one(
      { "grow_name" : current_grow},
      {
      '$set': {'device_name' : link_device, 'device_id' : device_id, 'sensors': [], 'actuators' : {}, 'controls' : {"time":[], "condition" :[]} }
      },
      upsert=True
      )
    return redirect(url_for('grows.list_grow', current_grow=current_grow))

@mod_grows.route('/edit_grows/<current_grow>', methods=['POST'])
@login_required
def edit_grow(current_grow):
    grows = db.grows.find({'grow_name':current_grow})
    for grow in grows:
        device_id = grow['device_id']
    devices = db.devices.find({'device_id':device_id})
    for device in devices:
{'fraction_non_alphanumeric': 0.16911021233569262, 'fraction_numerical': 0.003538928210313448, 'mean_word_length': 3.8103343465045594, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5855998', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2484, 'n_words': 433}