from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404

import math
import pandas as pd
from datetime import datetime as dt
import datetime
from dateutil import tz
import pandas_highcharts.core
import time

from graphs.models import Participants, Graphs


PATH_MAP = ['practice/greg/', 'practice/landon/', 'practice/thomas1/', 'practice/thomas2/', 'practice/jesus/',
            'practice/dylan/', 'practice/ivy/', 'practice/william/', 'practice/dominic/', 'match/greg/',
            'match/landon/', 'match/dylan/', 'match/william/']

SHOT_MARKERS = {
    'practice': {
        'greg': [(1510786161000, 9.3, 'green', 0.66847800000000002), (1510786188000, 10.0, 'green', 0.68895899999999999), (1510786232000, 9.3, 'green', 0.744004), (1510786284000, 9.5, 'green', 0.815689), (1510786317000, 9.8, 'green', 0.81312899999999999), (1510786345000, 9.0, 'green', 0.85281200000000013), (1510786462000, 9.8, 'green', 1.012893), (1510786494000, 9.6, 'green', 1.066657), (1510786674000, 10.0, 'green', 1.4610259999999999), (1510786702000, 9.3, 'green', 1.5826360000000002), (1510786744000, 10.5, 'green', 1.6658419999999998), (1510786810000, 10.5, 'green', 1.6402400000000001), (1510786845000, 9.0, 'green', 1.704245), (1510786931000, 10.3, 'green', 1.535272), (1510787009000, 9.7, 'green', 2.1703999999999999), (1510787048000, 10.6, 'green', 2.1102349999999999), (1510787098000, 8.6, 'gold', 2.6195400000000002), (1510787128000, 9.9, 'green', 2.884125), (1510787170000, 10.0, 'green', 3.2617529999999997), (1510787214000, 8.7, 'gold', 3.4040300000000001), (1510787275000, 10.3, 'green', 3.679853), (1510787327000, 9.7, 'green', 4.0459610000000001), (1510787420000, 9.9, 'green', 3.3948830000000001), (1510787937000, 9.4, 'green', 1.741368), (1510787983000, 10.2, 'green', 1.828414), (1510788030000, 10.1, 'green', 1.7631290000000002), (1510788072000, 9.1, 'green', 1.9924660000000001), (1510788117000, 9.7, 'green', 2.0910330000000004), (1510788165000, 9.8, 'green', 2.2318439999999997), (1510788209000, 10.7, 'green', 2.909726), (1510788268000, 10.0, 'green', 4.0805239999999996), (1510788303000, 10.0, 'green', 4.0382800000000003), (1510788410000, 9.6, 'green', 4.4266079999999999), (1510788441000, 10.5, 'green', 5.0290650000000001), (1510788478000, 10.6, 'green', 4.7180010000000001), (1510788526000, 9.7, 'green', 4.9906620000000004), (1510788579000, 9.1, 'green', 5.5274390000000002), (1510788621000, 10.2, 'green', 5.4531929999999997), (1510788670000, 9.4, 'green', 5.5210379999999999), (1510788783000, 8.2, 'gold', 5.2991660000000005), (1510789660000, 9.8, 'green', 1.3892420000000001), (1510789695000, 10.5, 'green', 1.435424), (1510789725000, 9.6, 'green', 1.51223), (1510789759000, 9.5, 'green', 1.7068049999999999), (1510789798000, 9.1, 'green', 1.9361419999999998), (1510789832000, 10.0, 'green', 2.5939380000000001), (1510789861000, 10.2, 'green', 2.793237), (1510789905000, 9.7, 'green', 3.7016150000000003), (1510789952000, 8.6, 'gold', 4.3352629999999994), (1510789989000, 10.3, 'green', 4.292198), (1510790034000, 10.5, 'green', 4.8178489999999998), (1510790096000, 9.3, 'green', 4.1701309999999996), (1510790165000, 9.1, 'green', 4.3327029999999995), (1510790196000, 10.2, 'green', 5.1519550000000001), (1510790219000, 10.1, 'green', 4.8524120000000002), (1510790260000, 8.4, 'gold', 5.1276330000000003), (1510790297000, 9.6, 'green', 5.1293280000000001), (1510790328000, 9.8, 'green', 4.5827800000000005), (1510790372000, 9.9, 'green', 5.3507850000000001), (1510790419000, 10.0, 'green', 0.0)],
        'thomas1': [(1510786205000, 9.8, 'green', 1.3212489999999999), (1510786247000, 9.8, 'green', 1.3942709999999998), (1510786289000, 6.8, 'red', 2.8535599999999999), (1510786317000, 10.1, 'green', 2.5525009999999999), (1510786478000, 8.2, 'gold', 3.3788110000000002), (1510786511000, 8.1, 'gold', 2.3573720000000002), (1510786697000, 8.5, 'gold', 2.8702139999999998), (1510786745000, 9.6, 'green', 3.0743480000000001), (1510786849000, 10.1, 'green', 3.5624470000000001), (1510786894000, 8.9, 'gold', 3.9912489999999998), (1510786968000, 8.4, 'gold', 5.0501480000000001), (1510787262000, 10.8, 'green', 2.0499080000000003), (1510787330000, 9.7, 'green', 3.1371220000000002), (1510787379000, 7.2, 'red', 4.3204910000000005), (1510787436000, 9.2, 'green', 4.6535769999999994), (1510787473000, 9.9, 'green', 5.0142769999999999), (1510787496000, 10.4, 'green', 5.1628850000000002), (1510787527000, 9.7, 'green', 4.6683810000000001), (1510787571000, 10.8, 'green', 5.272729), (1510787598000, 10.6, 'green', 5.7603150000000003), (1510787710000, 10.2, 'green', 6.9545630000000003), (1510787747000, 10.4, 'green', 6.4170870000000004), (1510787789000, 8.4, 'gold', 6.6656199999999997), (1510787813000, 9.3, 'green', 6.8418259999999993), (1510787847000, 9.6, 'green', 7.0416780000000001), (1510787880000, 10.2, 'green', 6.9058809999999999), (1510787981000, 10.3, 'green', 6.9174110000000004), (1510788080000, 9.1, 'green', 6.8846880000000006), (1510788099000, 8.1, 'gold', 6.5592889999999997), (1510788118000, 10.3, 'green', 6.8385690000000006), (1510788512000, 10.8, 'green', 2.665238), (1510788618000, 9.5, 'green', 3.8071370000000004), (1510788747000, 9.8, 'green', 4.4498819999999997), (1510788775000, 10.0, 'green', 3.8698309999999996), (1510788826000, 7.3, 'red', 5.0719269999999996), (1510788855000, 9.8, 'green', 4.526179), (1510788904000, 9.1, 'green', 5.3214110000000003), (1510788935000, 8.9, 'gold', 5.1817710000000003), (1510788960000, 10.8, 'green', 5.0587849999999994), (1510788982000, 9.6, 'green', 6.0613730000000006), (1510789008000, 8.0, 'gold', 5.8897059999999994), (1510789057000, 9.2, 'green', 6.0895570000000001), (1510789116000, 9.8, 'green', 5.6360480000000006), (1510789172000, 9.7, 'green', 5.9985989999999996), (1510789192000, 9.8, 'green', 6.1062120000000002), (1510789761000, 8.9, 'gold', 1.5469219999999999), (1510789784000, 9.5, 'green', 1.573825), (1510789812000, 9.7, 'green', 1.423737), (1510789860000, 9.7, 'green', 1.9415), (1510789907000, 9.4, 'green', 2.944518), (1510789939000, 9.7, 'green', 3.1213099999999998), (1510789973000, 9.9, 'green', 3.2396099999999999), (1510790015000, 8.4, 'gold', 4.8957050000000004), (1510790035000, 8.9, 'gold', 4.448601), (1510790093000, 10.4, 'green', 3.9018589999999995), (1510790178000, 8.6, 'gold', 4.3076800000000004), (1510790196000, 9.7, 'green', 4.3397079999999999), (1510790216000, 8.5, 'gold', 4.2333769999999999), (1510790237000, 10.4, 'green', 5.4815480000000001), (1510790260000, 9.7, 'green', 5.4994839999999998)],
        'thomas2': [(1510873135000, 9.3, 'green', 2.8303599999999998), (1510873223000, 10.1, 'green', 3.4123129999999997), (1510873252000, 9.8, 'green', 3.023841), (1510873284000, 7.7, 'red', 2.5576989999999999), (1510873307000, 9.6, 'green', 2.9174069999999999), (1510873335000, 8.8, 'gold', 3.8731480000000005), (1510873354000, 9.1, 'green', 3.003174), (1510873375000, 9.9, 'green', 3.6260889999999999), (1510873402000, 9.1, 'green', 3.9141110000000001), (1510873421000, 9.1, 'green', 3.9537940000000003), (1510873648000, 9.9, 'green', 1.8631759999999999), (1510873688000, 9.5, 'green', 2.1332770000000001), (1510873718000, 9.2, 'green', 2.2956750000000001), (1510873744000, 10.2, 'green', 2.4620880000000001), (1510873791000, 9.4, 'green', 3.076139), (1510873880000, 8.9, 'gold', 4.1897900000000003), (1510873901000, 10.4, 'green', 5.3853480000000005), (1510873929000, 9.1, 'green', 4.9245130000000001), (1510873967000, 8.6, 'gold', 5.0073040000000004), (1510873988000, 9.9, 'green', 4.8511309999999996), (1510874042000, 10.1, 'green', 4.3613230000000005), (1510874095000, 9.5, 'green', 4.5720700000000001), (1510874125000, 10.0, 'green', 4.4931730000000005), (1510874197000, 10.0, 'green', 4.1731489999999996), (1510874301000, 9.6, 'green', 3.5851260000000003), (1510874335000, 10.1, 'green', 3.8232239999999997), (1510874369000, 9.5, 'green', 4.8413059999999994), (1510874399000, 8.5, 'gold', 4.4402200000000001), (1510874424000, 9.5, 'green', 4.4150870000000006), (1510874446000, 10.5, 'green', 3.8104230000000001), (1510874782000, 9.9, 'green', 1.5329110000000001), (1510874807000, 9.4, 'green', 1.436704), (1510874826000, 10.2, 'green', 1.5147899999999999), (1510874893000, 8.8, 'gold', 2.271353), (1510874922000, 10.6, 'green', 2.076778), (1510874954000, 10.2, 'green', 2.2649529999999998), (1510874977000, 8.2, 'gold', 3.1300889999999999), (1510875005000, 8.7, 'gold', 3.3400249999999998), (1510875028000, 10.2, 'green', 3.6184080000000001), (1510875055000, 9.4, 'green', 3.812983), (1510875079000, 10.3, 'green', 3.3937889999999999), (1510875125000, 8.6, 'gold', 3.7016150000000003), (1510875173000, 9.5, 'green', 3.7387379999999997), (1510875194000, 7.0, 'red', 4.0741230000000002), (1510875251000, 10.2, 'green', 3.7604989999999998), (1510875280000, 8.0, 'gold', 4.3096610000000002), (1510875321000, 9.4, 'green', 4.287077), (1510875365000, 10.6, 'green', 4.6839079999999997), (1510875393000, 8.1, 'gold', 5.1472499999999997), (1510875414000, 8.8, 'gold', 4.709041), (1510875680000, 9.4, 'green', 2.3763209999999999), (1510875701000, 10.0, 'green', 2.35968), (1510875727000, 9.1, 'green', 2.208628), (1510875754000, 9.7, 'green', 2.3059159999999999), (1510875776000, 10.9, 'green', 2.2495919999999998), (1510875807000, 9.2, 'green', 2.2495919999999998), (1510875836000, 9.9, 'green', 2.2214290000000001), (1510875857000, 10.3, 'green', 2.1203020000000001), (1510875884000, 10.0, 'green', 2.5644960000000001), (1510875914000, 9.7, 'green', 3.4827180000000002)],
        'landon': [(1510873096000, 8.8, 'gold', 6.4584730000000006), (1510873132000, 9.7, 'green', 5.7103109999999999), (1510873179000, 5.4, 'red', 5.9710660000000004), (1510873205000, 7.1, 'red', 5.9595370000000001), (1510873234000, 8.5, 'gold', 5.6872509999999998), (1510873280000, 9.2, 'green', 6.4783819999999999), (1510873310000, 8.2, 'gold', 5.9672230000000006), (1510873336000, 8.9, 'gold', 6.0613320000000002), (1510873379000, 10.0, 'green', 5.8832599999999999), (1510873470000, 8.8, 'gold', 5.2739150000000006), (1510873518000, 10.5, 'green', 5.7756470000000002), (1510873542000, 8.9, 'gold', 5.9473150000000006), (1510873583000, 7.7, 'red', 5.37256), (1510873635000, 9.5, 'green', 5.0785599999999995), (1510873697000, 10.0, 'green', 5.733371), (1510873731000, 7.7, 'red', 5.3610300000000004), (1510873784000, 9.5, 'green', 5.6018759999999999), (1510873838000, 9.0, 'green', 5.4899620000000002), (1510874077000, 9.1, 'green', 4.58108), (1510874129000, 8.5, 'gold', 5.053566), (1510874180000, 9.5, 'green', 5.1509289999999996), (1510874236000, 9.9, 'green', 4.967104), (1510874291000, 7.9, 'red', 5.1880809999999995), (1510874323000, 9.7, 'green', 5.1528640000000001), (1510874351000, 8.7, 'gold', 4.4777250000000004), (1510874396000, 10.1, 'green', 5.3610300000000004), (1510874431000, 9.4, 'green', 5.5519129999999999), (1510874464000, 10.6, 'green', 5.9798010000000001), (1510874505000, 9.8, 'green', 5.8491290000000005), (1510874547000, 10.6, 'green', 5.0510029999999997), (1510874598000, 8.5, 'gold', 4.6980729999999999), (1510874658000, 10.1, 'green', 4.6519539999999999), (1510874702000, 9.3, 'green', 4.9799160000000002), (1510874745000, 10.2, 'green', 5.8102369999999999), (1510874773000, 10.3, 'green', 5.8491290000000005), (1510874801000, 7.2, 'red', 5.0369109999999999), (1510874845000, 9.9, 'green', 5.1419620000000004), (1510874893000, 8.1, 'gold', 5.4680140000000002), (1510874933000, 9.1, 'green', 5.1522100000000002), (1510875177000, 10.3, 'green', 4.1775339999999996), (1510875277000, 9.8, 'green', 5.1932049999999998), (1510875340000, 10.0, 'green', 4.9286709999999996), (1510875374000, 9.3, 'green', 4.8889580000000006), (1510875411000, 8.8, 'gold', 4.8799900000000003), (1510875447000, 8.4, 'gold', 4.6686079999999999), (1510875473000, 9.2, 'green', 4.9709479999999999), (1510875504000, 9.3, 'green', 4.6135209999999995), (1510875535000, 8.4, 'gold', 4.9927260000000002), (1510875567000, 10.2, 'green', 4.3312660000000003), (1510875650000, 10.4, 'green', 5.1426150000000002), (1510876072000, 9.4, 'green', 3.292735), (1510876141000, 10.9, 'green', 3.4631220000000003), (1510876194000, 9.2, 'green', 4.0153540000000003), (1510876233000, 7.2, 'red', 3.866746), (1510876276000, 10.7, 'green', 4.2608050000000004), (1510876340000, 9.8, 'green', 3.9333629999999999), (1510876443000, 7.6, 'red', 5.2444499999999996), (1510876570000, 9.0, 'green', 4.9568560000000002), (1510876629000, 9.8, 'green', 4.9760720000000003), (1510876666000, 8.4, 'gold', 5.6505580000000002)],
        'dylan': [(1510873069000, 10.7, 'green', 1.5710729999999999), (1510873090000, 10.1, 'green', 1.692763), (1510873110000, 10.0, 'green', 1.618468), (1510873148000, 9.4, 'green', 1.7196630000000002), (1510873174000, 10.7, 'green', 2.3883160000000001), (1510873210000, 8.4, 'gold', 2.3017189999999998), (1510873237000, 8.7, 'gold', 2.5092319999999999), (1510873258000, 8.6, 'gold', 2.4362180000000002), (1510873294000, 8.7, 'gold', 2.75081), (1510873333000, 9.6, 'green', 2.3029999999999999), (1510873384000, 10.1, 'green', 2.4310939999999999), (1510873432000, 10.5, 'green', 2.0865200000000002), (1510873458000, 9.9, 'green', 2.1313529999999998), (1510873477000, 9.7, 'green', 2.1134200000000001), (1510873523000, 9.9, 'green', 2.1928389999999998), (1510873546000, 9.8, 'green', 2.2223000000000002), (1510873568000, 10.1, 'green', 2.2965949999999999), (1510873591000, 10.4, 'green', 2.3094049999999999), (1510873614000, 9.8, 'green', 2.6534580000000001), (1510873635000, 10.6, 'green', 2.332462), (1510873682000, 9.0, 'green', 2.352957), (1510873707000, 10.5, 'green', 2.2927520000000001), (1510873732000, 10.6, 'green', 2.282505), (1510873750000, 10.8, 'green', 2.6219549999999998), (1510873768000, 10.1, 'green', 2.687284), (1510873787000, 8.6, 'gold', 2.42469), (1510873810000, 9.6, 'green', 2.438259), (1510873831000, 8.7, 'gold', 2.5612300000000001), (1510873862000, 9.1, 'green', 2.7123819999999998), (1510873911000, 10.2, 'green', 2.8468810000000002), (1510873931000, 10.5, 'green', 3.3416309999999996), (1510873949000, 10.4, 'green', 2.921176), (1510873967000, 7.6, 'red', 2.977843), (1510874002000, 9.4, 'green', 2.7687430000000002), (1510874019000, 9.8, 'green', 2.73672), (1510874061000, 8.1, 'gold', 2.822543), (1510874080000, 9.6, 'green', 2.7892380000000001), (1510874103000, 10.0, 'green', 3.0262130000000003), (1510874126000, 9.5, 'green', 2.9070849999999999), (1510874146000, 8.9, 'gold', 3.3544410000000005), (1510874178000, 8.4, 'gold', 3.8335140000000001), (1510874201000, 9.4, 'green', 3.3326639999999998), (1510874248000, 9.3, 'green', 3.2814269999999999), (1510874272000, 8.9, 'gold', 3.0380470000000002), (1510874821000, 9.6, 'green', 1.078991), (1510874853000, 9.3, 'green', 1.0264719999999998), (1510874882000, 9.5, 'green', 2.1692749999999998), (1510874901000, 7.0, 'red', 1.957919), (1510874917000, 9.8, 'green', 1.9438279999999999), (1510874932000, 9.6, 'green', 1.6837959999999998), (1510874958000, 10.7, 'green', 1.7311909999999999), (1510874977000, 9.1, 'green', 2.3516759999999999), (1510875000000, 10.3, 'green', 2.0744849999999997), (1510875018000, 8.8, 'gold', 2.2812240000000004), (1510875041000, 10.3, 'green', 2.1031720000000003), (1510875069000, 9.2, 'green', 2.0527090000000001), (1510875087000, 10.4, 'green', 2.310686), (1510875102000, 9.6, 'green', 2.6406490000000002), (1510875114000, 8.0, 'gold', 2.6713909999999998), (1510875128000, 8.6, 'gold', 2.3209330000000001)],
        'ivy': [(1510873129000, 10.4, 'green', 9.2455879999999997), (1510873193000, 9.6, 'green', 9.5012070000000008), (1510873220000, 8.6, 'gold', 9.3481059999999996), (1510873279000, 7.5, 'red', 8.5729070000000007), (1510873363000, 9.3, 'green', 7.7069589999999994), (1510873401000, 8.5, 'gold', 8.8009130000000013), (1510873534000, 8.9, 'gold', 7.5941880000000008), (1510873639000, 7.2, 'red', 7.9629199999999996), (1510873798000, 8.8, 'gold', 7.8003720000000003), (1510873867000, 9.4, 'green', 7.1371649999999995), (1510873915000, 9.2, 'green', 7.0628390000000003), (1510873957000, 8.6, 'gold', 7.136698), (1510874023000, 8.6, 'gold', 7.2058979999999995), (1510874153000, 9.7, 'green', 7.0538690000000006), (1510874179000, 10.3, 'green', 5.7998640000000004), (1510874212000, 8.6, 'gold', 6.5841330000000005), (1510874244000, 9.1, 'green', 6.8814369999999991), (1510874275000, 9.7, 'green', 6.7955779999999999), (1510874308000, 9.3, 'green', 7.4122170000000001), (1510874405000, 10.3, 'green', 6.7386229999999996), (1510874538000, 9.8, 'green', 6.9616020000000001), (1510874564000, 9.2, 'green', 7.0782169999999995), (1510874675000, 9.4, 'green', 6.2233429999999998), (1510874757000, 10.3, 'green', 6.6533329999999999), (1510874933000, 8.9, 'gold', 6.4918659999999999), (1510875019000, 9.8, 'green', 5.8239780000000003), (1510875357000, 8.5, 'gold', 4.6917989999999996), (1510875438000, 9.7, 'green', 3.8794440000000003), (1510875473000, 10.2, 'green', 4.5722069999999997), (1510875707000, 9.4, 'green', 3.1412299999999997), (1510875742000, 10.5, 'green', 2.9628459999999999), (1510875777000, 10.3, 'green', 3.4321269999999995), (1510875961000, 10.5, 'green', 2.3464509999999996), (1510876032000, 8.9, 'gold', 3.4910760000000001), (1510876065000, 9.2, 'green', 3.1448160000000001), (1510876098000, 9.7, 'green', 2.9795050000000001), (1510876305000, 10.7, 'green', 2.8321339999999999), (1510876371000, 9.8, 'green', 2.7257709999999999), (1510876463000, 8.9, 'gold', 2.274489), (1510876498000, 10.3, 'green', 3.0126249999999999), (1510876531000, 10.3, 'green', 2.5961419999999999), (1510876561000, 10.0, 'green', 2.5359119999999997), (1510876621000, 8.0, 'gold', 2.7512020000000001), (1510876656000, 8.2, 'gold', 2.9141490000000001), (1510876681000, 10.3, 'green', 2.526942), (1510876704000, 9.2, 'green', 2.2719259999999997), (1510876735000, 10.2, 'green', 2.2475779999999999), (1510876805000, 10.3, 'green', 2.4910600000000001), (1510876896000, 10.4, 'green', 1.7921509999999998), (1510876962000, 9.3, 'green', 1.5512319999999999), (1510877027000, 9.7, 'green', 1.6268389999999999), (1510877050000, 10.8, 'green', 1.981811), (1510877076000, 8.5, 'gold', 2.1463410000000001), (1510877184000, 7.4, 'red', 1.9669330000000003), (1510877300000, 10.4, 'green', 1.761395), (1510877391000, 8.3, 'gold', 1.647343), (1510877430000, 8.4, 'gold', 1.5254030000000001), (1510877466000, 9.9, 'green', 1.8164990000000001), (1510877504000, 7.7, 'red', 2.0164110000000002), (1510877538000, 9.4, 'green', 2.279115)],
        'jesus': [(1510873156000, 9.7, 'green', 17.414789000000003), (1510873221000, 8.2, 'gold', 18.771377999999999), (1510873298000, 8.6, 'gold', 18.302965), (1510873326000, 9.9, 'green', 18.775879), (1510873384000, 9.1, 'green', 18.740009000000001), (1510873429000, 8.4, 'gold', 18.928944000000001), (1510873509000, 10.0, 'green', 18.413132000000001), (1510873532000, 8.7, 'gold', 18.397760000000002), (1510873557000, 10.2, 'green', 18.474838000000002), (1510873579000, 10.7, 'green', 18.190235000000001), (1510873606000, 8.0, 'gold', 18.304245000000002), (1510873631000, 10.1, 'green', 17.604382000000001), (1510873657000, 9.6, 'green', 17.864429000000001), (1510873685000, 10.6, 'green', 17.204681000000001), (1510873718000, 8.3, 'gold', 17.910973000000002), (1510873740000, 9.0, 'green', 17.170093999999999), (1510873768000, 9.2, 'green', 16.627476000000001), (1510873796000, 9.5, 'green', 16.733264999999999), (1510873826000, 9.8, 'green', 18.425943), (1510873853000, 9.9, 'green', 18.33905), (1510874307000, 9.9, 'green', 8.5883369999999992), (1510874375000, 10.2, 'green', 11.291917999999999), (1510874419000, 10.4, 'green', 10.12102), (1510874445000, 9.7, 'green', 10.83203), (1510874508000, 10.2, 'green', 10.156889), (1510874531000, 8.8, 'gold', 9.8243840000000002), (1510874557000, 8.3, 'gold', 9.3465619999999987), (1510874585000, 9.0, 'green', 9.3183799999999994), (1510874613000, 9.4, 'green', 8.9956420000000001), (1510874642000, 8.7, 'gold', 9.7718619999999987), (1510874667000, 10.1, 'green', 10.109491), (1510874715000, 8.5, 'gold', 9.4618549999999999), (1510874737000, 10.1, 'green', 9.5797880000000006), (1510874770000, 10.3, 'green', 9.9147759999999998), (1510874815000, 9.7, 'green', 9.8929989999999997), (1510874847000, 10.4, 'green', 9.3888369999999988), (1510874870000, 10.5, 'green', 8.9405579999999993), (1510874892000, 8.5, 'gold', 9.4747450000000004), (1510874914000, 9.6, 'green', 9.6918779999999991), (1510874930000, 9.4, 'green', 10.049844), (1510875561000, 8.4, 'gold', 3.5532660000000003), (1510875587000, 8.6, 'gold', 3.476404), (1510875611000, 10.0, 'green', 3.3021849999999997), (1510875634000, 10.3, 'green', 3.167678), (1510875660000, 9.9, 'green', 3.0301689999999999), (1510875683000, 9.1, 'green', 2.8444210000000001), (1510875705000, 8.8, 'gold', 2.69326), (1510875740000, 9.6, 'green', 2.6057480000000002), (1510875767000, 10.6, 'green', 2.6416169999999997), (1510875788000, 10.4, 'green', 2.5173580000000002), (1510875805000, 10.2, 'green', 2.5596320000000001), (1510875828000, 9.2, 'green', 2.8085520000000002), (1510875855000, 9.3, 'green', 3.15699), (1510875877000, 10.6, 'green', 3.5801669999999999), (1510875898000, 9.1, 'green', 4.4342420000000002), (1510875922000, 10.3, 'green', 5.134061), (1510875947000, 10.1, 'green', 5.1407970000000001), (1510875973000, 9.3, 'green', 5.5837000000000003), (1510875996000, 10.4, 'green', 5.8944749999999999), (1510876014000, 9.3, 'green', 6.5857960000000002)],
        'william': [(1510959725000, 9.0, 'green', 1.1994), (1510959766000, 9.9, 'green', 2.0852390000000001), (1510959949000, 9.1, 'green', 2.8148569999999999), (1510959981000, 9.2, 'green', 2.4772080000000001), (1510960087000, 9.0, 'green', 2.7175050000000001), (1510960119000, 10.2, 'green', 2.6124680000000002), (1510960199000, 9.1, 'green', 2.5612300000000001), (1510960230000, 9.7, 'green', 2.4848939999999997), (1510960388000, 9.3, 'green', 2.8122950000000002), (1510960453000, 10.0, 'green', 2.4208470000000002), (1510960490000, 10.7, 'green', 2.4964230000000001), (1510960552000, 8.8, 'gold', 2.7777099999999999), (1510960609000, 10.3, 'green', 2.7456860000000001), (1510960665000, 9.5, 'green', 2.474126), (1510960696000, 9.1, 'green', 2.9467950000000003), (1510960733000, 8.9, 'gold', 2.4848939999999997), (1510960796000, 9.1, 'green', 2.8750619999999998), (1510960825000, 8.8, 'gold', 2.4433830000000003), (1510960852000, 10.4, 'green', 2.4144419999999998), (1510960879000, 8.8, 'gold', 2.1953999999999998), (1510960905000, 10.2, 'green', 2.4989849999999998), (1510960940000, 8.6, 'gold', 2.8904330000000003), (1510960966000, 8.8, 'gold', 2.6573009999999999), (1510961024000, 10.0, 'green', 2.5246029999999999), (1510961058000, 9.0, 'green', 2.1813099999999999), (1510961205000, 8.8, 'gold', 2.232548), (1510961230000, 10.7, 'green', 2.4195660000000001), (1510961286000, 9.4, 'green', 2.2671330000000003), (1510961318000, 8.7, 'gold', 3.7938050000000003), (1510961345000, 8.9, 'gold', 2.6893250000000002), (1510961510000, 8.4, 'gold', 1.8321869999999998), (1510961551000, 9.0, 'green', 1.7233060000000002), (1510961623000, 7.9, 'red', 1.749125), (1510962016000, 9.7, 'green', 1.488893), (1510962167000, 7.4, 'red', 2.6662669999999999), (1510962561000, 10.1, 'green', 0.59334500000000001), (1510962621000, 9.5, 'green', 0.63049200000000005), (1510962657000, 9.9, 'green', 0.55875900000000001), (1510962681000, 9.1, 'green', 0.54210700000000001), (1510962744000, 8.6, 'gold', 0.69710099999999997), (1510962809000, 8.0, 'gold', 1.0098200000000002), (1510962836000, 8.4, 'gold', 1.4878120000000001), (1510962864000, 8.3, 'gold', 1.7220259999999998), (1510962922000, 9.6, 'green', 1.501703), (1510962987000, 8.6, 'gold', 1.7245869999999999), (1510963019000, 7.6, 'red', 1.461994), (1510963055000, 10.0, 'green', 1.039183), (1510963092000, 8.8, 'gold', 1.0097209999999999), (1510963120000, 9.9, 'green', 1.5426930000000001), (1510963153000, 9.4, 'green', 1.103329), (1510963264000, 8.8, 'gold', 0.70741799999999999), (1510963325000, 8.3, 'gold', 1.2351669999999999), (1510963350000, 8.5, 'gold', 0.89827900000000005), (1510963368000, 9.0, 'green', 1.099486), (1510963395000, 7.7, 'red', 1.6733499999999999), (1510963416000, 9.0, 'green', 1.140476), (1510963439000, 9.8, 'green', 1.355675), (1510963477000, 10.5, 'green', 1.0712059999999999), (1510963498000, 9.9, 'green', 1.039183), (1510963515000, 10.8, 'green', 0.90212099999999995)],
        'dominic': [(1510959364000, 7.4, 'red', 2.2963040000000001), (1510959396000, 6.5, 'red', 2.976086), (1510959441000, 9.7, 'green', 3.6011870000000004), (1510959483000, 7.6, 'red', 4.3122540000000003), (1510959529000, 9.7, 'green', 4.2635779999999999), (1510959562000, 10.2, 'green', 4.7497290000000003), (1510959590000, 3.9, 'red', 4.9777370000000003), (1510959627000, 8.7, 'gold', 5.3757349999999997), (1510959666000, 10.4, 'green', 5.681152), (1510959702000, 7.2, 'red', 5.4390540000000005), (1510959742000, 6.8, 'red', 5.3706110000000002), (1510959794000, 8.3, 'gold', 5.2899120000000002), (1510959840000, 7.9, 'red', 5.8976319999999998), (1510959866000, 7.3, 'red', 5.799728), (1510959905000, 9.5, 'green', 5.8899460000000001), (1510959942000, 7.7, 'red', 5.2578879999999995), (1510959994000, 9.7, 'green', 5.3142500000000004), (1510960025000, 10.3, 'green', 5.1336360000000001), (1510960051000, 9.5, 'green', 5.2258639999999996), (1510960079000, 7.0, 'red', 5.1784699999999999), (1510960401000, 8.1, 'gold', 3.8428960000000001), (1510960440000, 9.8, 'green', 3.4538790000000001), (1510960489000, 10.4, 'green', 3.052943), (1510960535000, 9.1, 'green', 2.9927380000000001), (1510960580000, 9.0, 'green', 2.9012029999999998), (1510960627000, 10.4, 'green', 2.892236), (1510960680000, 9.9, 'green', 2.7743889999999998), (1510960729000, 9.6, 'green', 2.4628269999999999), (1510960777000, 10.3, 'green', 3.0004240000000002), (1510960804000, 10.4, 'green', 2.6988129999999999), (1510960899000, 8.8, 'gold', 2.4269609999999999), (1510960947000, 7.5, 'red', 3.7429830000000002), (1510961005000, 9.2, 'green', 5.2134309999999999), (1510961050000, 6.8, 'red', 4.9495569999999995), (1510961092000, 9.8, 'green', 4.3596490000000001), (1510961148000, 9.2, 'green', 4.6357249999999999), (1510961195000, 9.0, 'green', 4.7561339999999994), (1510961241000, 9.5, 'green', 4.4236959999999996), (1510961278000, 7.0, 'red', 4.5486209999999998), (1510961318000, 8.0, 'gold', 4.4794499999999999), (1510961692000, 8.0, 'gold', 4.3109730000000006), (1510961736000, 10.0, 'green', 4.2822610000000001), (1510961778000, 10.5, 'green', 3.6434589999999996), (1510961819000, 8.9, 'gold', 4.0944929999999999), (1510961860000, 10.8, 'green', 4.0388809999999999), (1510961904000, 10.0, 'green', 3.8633919999999997), (1510961935000, 10.4, 'green', 4.6177919999999997), (1510961964000, 9.2, 'green', 6.637594), (1510961991000, 9.2, 'green', 4.6344440000000002), (1510962040000, 9.2, 'green', 4.3558059999999994), (1510962352000, 9.7, 'green', 4.7766289999999998), (1510962386000, 8.8, 'gold', 4.9828609999999998), (1510962430000, 8.9, 'gold', 4.8970379999999993), (1510962469000, 9.1, 'green', 4.407044), (1510962511000, 9.0, 'green', 4.772786), (1510962541000, 10.0, 'green', 4.8278669999999995), (1510962565000, 8.4, 'gold', 5.2066499999999998), (1510962598000, 9.1, 'green', 4.7817530000000001), (1510962618000, 8.7, 'gold', 5.4000729999999999), (1510962646000, 8.5, 'gold', 5.6408910000000008)]
    },
    'match': {
        'dylan': [(1511038991000, 7.9, 'red', 2.6209549999999999), (1511039056000, 9.7, 'green', 2.578681), (1511039103000, 8.5, 'gold', 3.8389359999999999), (1511039131000, 8.3, 'gold', 3.725857), (1511039234000, 9.1, 'green', 4.271922), (1511039277000, 10.7, 'green', 4.7625539999999997), (1511039302000, 9.3, 'green', 4.6583050000000004), (1511039322000, 10.8, 'green', 4.6519000000000004), (1511039345000, 10.6, 'green', 4.5250789999999999), (1511039372000, 9.6, 'green', 4.6498239999999997), (1511039395000, 8.5, 'gold', 4.8056230000000006), (1511039422000, 10.1, 'green', 5.5497879999999995), (1511039445000, 9.9, 'green', 4.8517390000000002), (1511039479000, 9.8, 'green', 4.4679180000000001), (1511039507000, 9.5, 'green', 4.365437), (1511039530000, 8.8, 'gold', 4.6980170000000001), (1511039556000, 10.4, 'green', 4.4884149999999998), (1511039579000, 10.0, 'green', 4.4115529999999996), (1511039602000, 9.5, 'green', 4.8504589999999999), (1511039654000, 10.1, 'green', 4.7454150000000004), (1511039677000, 10.1, 'green', 5.0541410000000004), (1511039699000, 10.2, 'green', 4.5801629999999998), (1511039721000, 9.2, 'green', 5.0016189999999998), (1511039745000, 9.3, 'green', 4.6980170000000001), (1511039791000, 10.3, 'green', 4.9964949999999995), (1511039812000, 8.9, 'gold', 4.6877680000000002), (1511039836000, 10.0, 'green', 4.9490970000000001), (1511039863000, 9.7, 'green', 6.0993469999999999), (1511039891000, 8.2, 'gold', 4.7953739999999998), (1511039919000, 10.7, 'green', 5.0387690000000003), (1511039946000, 10.6, 'green', 4.962224), (1511039968000, 9.0, 'green', 5.023396), (1511039999000, 10.4, 'green', 5.1979329999999999), (1511040083000, 9.5, 'green', 5.6138389999999996), (1511040111000, 9.9, 'green', 5.2273959999999997), (1511040144000, 9.9, 'green', 5.7752480000000004), (1511040177000, 9.3, 'green', 5.0518960000000002), (1511040203000, 8.5, 'gold', 5.5036719999999999), (1511040226000, 10.1, 'green', 5.1569400000000005), (1511040252000, 8.3, 'gold', 5.3145059999999997), (1511040329000, 10.3, 'green', 5.0775169999999994), (1511040359000, 9.6, 'green', 5.1569400000000005), (1511040381000, 9.8, 'green', 5.0211519999999998), (1511040407000, 9.8, 'green', 5.4502940000000004), (1511040430000, 9.5, 'green', 5.8085550000000001), (1511040452000, 7.7, 'red', 5.3106629999999999), (1511040643000, 10.3, 'green', 4.3116339999999997), (1511040663000, 8.7, 'gold', 4.139977), (1511040684000, 9.4, 'green', 4.1233230000000001), (1511040706000, 7.5, 'red', 4.371842), (1511040727000, 10.7, 'green', 3.9952209999999999), (1511040761000, 10.2, 'green', 3.8526790000000002), (1511040784000, 9.2, 'green', 3.8731749999999998), (1511040800000, 9.9, 'green', 4.4379689999999998), (1511040817000, 9.7, 'green', 4.8094660000000005), (1511040834000, 9.8, 'green', 4.5699139999999998), (1511040856000, 7.9, 'red', 4.6621480000000002), (1511040878000, 9.9, 'green', 6.4939019999999994), (1511040898000, 10.1, 'green', 5.1723120000000007), (1511040915000, 9.0, 'green', 5.1441300000000005)],
        'william': [(1511039104000, 8.6, 'gold', 4.2768930000000003), (1511039255000, 9.2, 'green', 6.9809449999999993), (1511039483000, 8.6, 'gold', 8.2336650000000002), (1511039570000, 9.0, 'green', 8.6253250000000001), (1511039629000, 9.6, 'green', 9.3678710000000009), (1511039660000, 8.6, 'gold', 9.4306029999999996), (1511039704000, 10.4, 'green', 8.70214), (1511039765000, 8.9, 'gold', 8.6880570000000006), (1511039791000, 9.9, 'green', 8.7406439999999996), (1511039851000, 10.1, 'green', 8.9569100000000006), (1511039908000, 9.2, 'green', 7.8113089999999996), (1511039945000, 9.3, 'green', 8.6726939999999999), (1511040048000, 7.4, 'red', 10.626499000000001), (1511040134000, 8.9, 'gold', 11.537861999999999), (1511040432000, 9.6, 'green', 5.9642520000000001), (1511040491000, 9.6, 'green', 5.7914180000000002), (1511040513000, 9.6, 'green', 5.2042000000000002), (1511040638000, 10.5, 'green', 5.387276), (1511040665000, 10.7, 'green', 5.517862), (1511040781000, 9.4, 'green', 5.2592509999999999), (1511040812000, 10.4, 'green', 4.7044860000000002), (1511040863000, 9.7, 'green', 5.5127410000000001), (1511040895000, 9.1, 'green', 4.7825819999999997), (1511040934000, 9.7, 'green', 4.5065160000000004), (1511041194000, 10.4, 'green', 4.5334010000000005), (1511041280000, 9.6, 'green', 4.537242), (1511041360000, 9.5, 'green', 4.7390530000000002), (1511041380000, 10.7, 'green', 4.8017849999999997), (1511041433000, 10.1, 'green', 4.2299819999999997), (1511041535000, 9.9, 'green', 4.0673900000000005), (1511041566000, 9.6, 'green', 4.2555870000000002), (1511041642000, 10.1, 'green', 3.9888370000000002), (1511041667000, 9.4, 'green', 4.1680720000000004), (1511041691000, 10.2, 'green', 4.0246830000000005), (1511041709000, 10.5, 'green', 3.6905379999999997), (1511041758000, 10.0, 'green', 3.278975), (1511041781000, 10.8, 'green', 3.170153), (1511041825000, 9.6, 'green', 3.5145410000000004), (1511041853000, 9.3, 'green', 3.4863749999999998), (1511041891000, 9.9, 'green', 3.198318), (1511041993000, 9.8, 'green', 3.2456879999999999), (1511042074000, 10.0, 'green', 3.0434080000000003), (1511042158000, 9.9, 'green', 3.0739490000000003), (1511042205000, 10.4, 'green', 2.8166180000000001), (1511042229000, 9.6, 'green', 2.985611), (1511042276000, 10.3, 'green', 2.853745), (1511042334000, 9.3, 'green', 2.8742290000000001), (1511042354000, 10.1, 'green', 2.6706689999999997), (1511042520000, 10.4, 'green', 2.3382000000000001), (1511042630000, 6.8, 'red', 3.7647919999999999), (1511042728000, 9.1, 'green', 3.5644709999999997), (1511042750000, 10.6, 'green', 3.0856560000000002), (1511042773000, 9.3, 'green', 3.4710120000000004), (1511042797000, 8.4, 'gold', 3.2072799999999999), (1511042841000, 9.7, 'green', 3.7699129999999998), (1511042865000, 10.2, 'green', 3.9726510000000004), (1511042893000, 8.4, 'gold', 4.3362429999999996), (1511042939000, 9.7, 'green', 4.2376629999999995), (1511043022000, 8.7, 'gold', 3.9773139999999998), (1511043065000, 9.9, 'green', 4.443784)],
        'greg': [(1511038999000, 9.9, 'green', 0.61643900000000007), (1511039025000, 9.2, 'green', 0.62284399999999995), (1511039053000, 9.8, 'green', 0.62412500000000004), (1511039084000, 9.7, 'green', 0.62924899999999995), (1511039114000, 10.1, 'green', 0.63693500000000003), (1511039149000, 8.5, 'gold', 0.64333999999999991), (1511039190000, 9.7, 'green', 0.64974500000000002), (1511039226000, 10.0, 'green', 0.65230699999999997), (1511039255000, 9.0, 'green', 0.65743099999999999), (1511039288000, 9.3, 'green', 0.66383700000000001), (1511039321000, 9.6, 'green', 0.67536600000000002), (1511039357000, 10.7, 'green', 0.67536600000000002), (1511039395000, 10.4, 'green', 0.69842399999999993), (1511039430000, 10.3, 'green', 0.72148299999999999), (1511039468000, 9.9, 'green', 0.72916899999999996), (1511039497000, 9.7, 'green', 0.73685500000000004), (1511039530000, 9.3, 'green', 0.74197899999999994), (1511039578000, 10.4, 'green', 0.77784799999999998), (1511039601000, 9.0, 'green', 0.78681499999999993), (1511039634000, 9.6, 'green', 0.79193900000000006), (1511039693000, 10.1, 'green', 0.82140200000000008), (1511039733000, 10.7, 'green', 0.84317999999999993), (1511039768000, 9.1, 'green', 0.86239500000000002), (1511039805000, 10.2, 'green', 0.920041), (1511039839000, 10.7, 'green', 1.0173989999999999), (1511039874000, 8.6, 'gold', 1.073833), (1511039904000, 10.5, 'green', 1.0828), (1511039971000, 9.2, 'green', 1.3236319999999999), (1511040010000, 9.5, 'green', 1.553034), (1511040061000, 9.6, 'green', 1.8169249999999999), (1511040101000, 10.6, 'green', 1.8233299999999999), (1511040145000, 10.4, 'green', 1.7415439999999998), (1511040195000, 10.3, 'green', 1.8260909999999999), (1511040241000, 8.5, 'gold', 1.7722880000000001), (1511040288000, 9.7, 'green', 2.159157), (1511040331000, 10.4, 'green', 2.3059889999999998), (1511040373000, 8.2, 'gold', 2.659551), (1511040418000, 8.2, 'gold', 2.7748430000000002), (1511040460000, 9.3, 'green', 2.9417789999999999), (1511040500000, 10.1, 'green', 2.91872), (1511040854000, 9.8, 'green', 1.9336970000000002), (1511040891000, 10.3, 'green', 1.9388209999999999), (1511040962000, 9.7, 'green', 2.0669240000000002), (1511041015000, 8.1, 'gold', 2.408471), (1511041048000, 10.2, 'green', 2.5801279999999998), (1511041083000, 10.7, 'green', 2.5984639999999999), (1511041137000, 9.7, 'green', 2.6778880000000003), (1511041173000, 9.3, 'green', 2.7983039999999999), (1511041222000, 9.8, 'green', 3.28125), (1511041267000, 10.5, 'green', 3.3017460000000001), (1511041312000, 9.4, 'green', 3.312433), (1511041359000, 10.4, 'green', 3.4969010000000003), (1511041408000, 9.4, 'green', 3.7414959999999997), (1511041442000, 7.8, 'red', 4.0681570000000002), (1511041476000, 8.8, 'gold', 4.2923359999999997), (1511041544000, 9.6, 'green', 4.7660269999999993), (1511041579000, 10.7, 'green', 4.9563300000000003), (1511041623000, 9.9, 'green', 4.8115740000000002), (1511041663000, 10.6, 'green', 4.8333519999999996), (1511041695000, 10.6, 'green', 4.964016)],
        'landon': [(1511039024000, 8.8, 'gold', 13.181679999999998), (1511039046000, 7.2, 'red', 12.806363000000001), (1511039069000, 7.2, 'red', 13.035489999999999), (1511039099000, 8.6, 'gold', 13.058709), (1511039120000, 8.5, 'gold', 14.175804000000001), (1511039164000, 10.4, 'green', 13.298083999999999), (1511039197000, 10.6, 'green', 13.129), (1511039258000, 8.0, 'gold', 12.957514), (1511039281000, 10.3, 'green', 12.889625000000001), (1511039312000, 9.4, 'green', 12.789710000000001), (1511039342000, 9.4, 'green', 12.712396999999999), (1511039364000, 10.5, 'green', 12.462612), (1511039384000, 8.8, 'gold', 12.415217), (1511039411000, 10.2, 'green', 12.832806), (1511039433000, 10.5, 'green', 11.987052), (1511039455000, 9.1, 'green', 11.899948), (1511039486000, 9.2, 'green', 13.231636999999999), (1511039524000, 10.1, 'green', 12.712396999999999), (1511039556000, 7.9, 'red', 12.553559), (1511039582000, 7.4, 'red', 12.052710000000001), (1511039616000, 8.9, 'gold', 11.94478), (1511039649000, 8.8, 'gold', 12.255099000000001), (1511039674000, 9.8, 'green', 11.674066999999999), (1511039732000, 10.4, 'green', 11.607892), (1511039756000, 9.5, 'green', 12.762354), (1511039800000, 10.2, 'green', 11.500292999999999), (1511039881000, 7.4, 'red', 12.486950999999999), (1511039966000, 9.3, 'green', 10.600896000000001), (1511040030000, 9.0, 'green', 10.439827000000001), (1511040060000, 9.8, 'green', 11.634357000000001), (1511040281000, 10.2, 'green', 9.7177139999999991), (1511040305000, 10.3, 'green', 9.3822089999999996), (1511040443000, 7.2, 'red', 8.8673320000000011), (1511040506000, 9.4, 'green', 9.1759769999999996), (1511040591000, 7.9, 'red', 10.862209), (1511040681000, 9.2, 'green', 8.8314649999999997), (1511040732000, 9.0, 'green', 8.7584509999999991), (1511040773000, 9.1, 'green', 8.4745030000000003), (1511040818000, 9.2, 'green', 8.933878), (1511040858000, 9.9, 'green', 7.9202039999999991), (1511040896000, 8.6, 'gold', 7.8945850000000002), (1511040931000, 10.3, 'green', 7.6601720000000002), (1511040996000, 6.7, 'red', 8.5650279999999999), (1511041031000, 10.0, 'green', 8.7161799999999996), (1511041067000, 7.5, 'red', 7.9621250000000003), (1511041096000, 9.0, 'green', 8.1414570000000008), (1511041114000, 9.2, 'green', 8.3518820000000016), (1511041155000, 8.7, 'gold', 9.4206369999999993), (1511041191000, 10.3, 'green', 8.8263420000000004), (1511041222000, 9.8, 'green', 8.4066119999999991), (1511041249000, 8.5, 'gold', 9.1490759999999991), (1511041291000, 9.4, 'green', 9.0670970000000004), (1511041312000, 10.0, 'green', 8.8903879999999997), (1511041347000, 9.8, 'green', 9.1862240000000011), (1511041380000, 9.3, 'green', 9.3911750000000005), (1511041405000, 8.3, 'gold', 9.1107110000000002), (1511041429000, 9.5, 'green', 9.4090059999999998), (1511041454000, 8.7, 'gold', 9.8702490000000012), (1511041498000, 7.1, 'red', 10.153846000000001), (1511041519000, 8.5, 'gold', 10.849730000000001)]
    }
}

BREATHING_HOURS_OFFSET = {
    'graphs/data/match/dylan/': 6,
    'graphs/data/practice/dylan/': 7,
    'graphs/data/match/william/': 5,
    'graphs/data/match/greg/': 7,
    'graphs/data/match/landon/': 7
}

def index(request):
    template = loader.get_template('../templates/home.html')
    context = {
        'title': 'Affect as Factor of Precision Performance',
        'author': 'William Caruso',
        'email': 'wcaruso@mit.edu'
    }
    return HttpResponse(template.render(context, request))


def graph(request):
    template = loader.get_template('../templates/graph.html')
    r_path = request.path
    participant_id = PATH_MAP[int(r_path[len(r_path)-2:])]
    path = 'graphs/data/' + participant_id

    p = participant_id.split('/')
    markers = SHOT_MARKERS[p[0]][p[1]]
    mod_markers = []
    graphs = None
    score = 0
    for i in range(len(markers)):
        time, sc, color, eda = markers[i]
        score += math.floor(sc)
        mod_markers.append((time, sc, color, eda, i+1))

    if len(Participants.objects.filter(shooter_id=participant_id)) > 0:
        graphs = Participants.objects.get(shooter_id=participant_id).graphs
        eda_chart = graphs.eda
        acc_chart = graphs.acc_raw
        bvp_chart = graphs.bvp
    else:
        # EDA
        # eda_stream_left = read_eda(path, 'left')
        eda_stream_right = read_eda(path, 'right')
        eda_chart = pandas_highcharts.core.serialize(eda_stream_right, render_to='eda-chart', output_type='json', title="Electrodermal Activity", zoom='x')

        # ACC
        # acc_stream_left = read_acc_seperate(path, 'left')
        acc_stream_right = read_acc_seperate(path, 'right')
        acc_chart = pandas_highcharts.core.serialize(acc_stream_right, render_to='acc-chart', output_type='json', title="Acceleration", zoom='x')

        # BVP
        # bvp_stream_left = read_bvp(path, 'left')
        bvp_stream_right = read_bvp(path, 'right')
        bvp_chart = pandas_highcharts.core.serialize(bvp_stream_right, render_to='bvp-chart', output_type='json', title="Blood Volume Pulse", zoom='x')

        g = Graphs(eda=eda_chart, bvp=bvp_chart, acc_raw=acc_chart)
        g.save()
        participant = Participants(name=p[1], shooter_id=participant_id, graphs=g)
        participant.save()

    breathing_stream, hr_stream = read_breathing_waveform(path)
    breathing_graph = pandas_highcharts.core.serialize(breathing_stream, render_to='breathing-chart', output_type='json', title="Breathing Rate", zoom='x')
    hr_graph = pandas_highcharts.core.serialize(hr_stream, render_to='hr-chart', output_type='json', title="Heart Rate", zoom='x')

    acc_stream = read_acc(path, 'left')
    acc_graph = pandas_highcharts.core.serialize(acc_stream, render_to='acc-ss-chart', output_type='json', title="Acceleration sqrt", zoom='x')

    graphs.hr = hr_graph
    graphs.breathing = breathing_graph
    graphs.acc = acc_graph
    graphs.save()

    context = {
        'player_id': int(r_path[len(r_path)-2:]),
        'name': participant_id,
        'score': score,
        'edaChart': eda_chart,
        'accChart': acc_chart,
        'accSsChart': acc_graph,
        'bvpChart': bvp_chart,
        'markers': mod_markers,
        'breathingChart': breathing_graph,
        'hrChart': hr_graph,
    }
    return HttpResponse(template.render(context, request))


# ---------------------------------------------------------------------------------------------------------------------

def read_eda(path, side):
    eda_filepath = path + side + '/EDA.csv'

    #read eda file
    eda_csv_stream = pd.read_csv(eda_filepath, header=None, names=[side + ' eda'])
    eda_csv_initial_timestamp = dt.utcfromtimestamp(eda_csv_stream.ix[0, side + ' eda'])
    eda_csv_initial_timestamp = eda_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    eda_csv_initial_timestamp = eda_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    eda_csv_stream = eda_csv_stream.drop(eda_csv_stream.index[:2])
    # add index
    index_eda_1 = pd.date_range(start=eda_csv_initial_timestamp, periods=len(eda_csv_stream.index), freq='250L')
    eda_csv_stream.set_index(index_eda_1, inplace=True)

    return eda_csv_stream


def read_acc_seperate(path, side):
    acc_filepath = path + side + '/ACC.csv'

    # read acc file
    print('Start Reading ACC file')
    x_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' x'], usecols=[0])
    acc_csv_initial_timestamp = dt.utcfromtimestamp(x_acc_csv_stream.ix[0, side + ' x'])
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    x_acc_csv_stream = x_acc_csv_stream.drop(x_acc_csv_stream.index[:2])
    x_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(x_acc_csv_stream.index), freq='31250U')
    x_acc_csv_stream.set_index(x_index_acc, inplace=True)

    y_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' y'], usecols=[1])
    y_acc_csv_stream = y_acc_csv_stream.drop(y_acc_csv_stream.index[:2])
    y_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(y_acc_csv_stream.index), freq='31250U')
    y_acc_csv_stream.set_index(y_index_acc, inplace=True)


    z_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' z'], usecols=[2])
    z_acc_csv_stream = z_acc_csv_stream.drop(z_acc_csv_stream.index[:2])
    z_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(z_acc_csv_stream.index), freq='31250U')
    z_acc_csv_stream.set_index(z_index_acc, inplace=True)

    return [x_acc_csv_stream, y_acc_csv_stream, z_acc_csv_stream]


def read_acc(path, side):
    acc_filepath = path + side + '/ACC.csv'

    # read acc file
    print('Start Reading ACC file')
    acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=['x', 'y', 'z'])
    acc_csv_initial_timestamp = dt.utcfromtimestamp(acc_csv_stream.ix[0, 'x'])
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    acc_csv_stream = acc_csv_stream.drop(acc_csv_stream.index[:2])
    index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(acc_csv_stream.index), freq='31250U')

    # calculate rolling avg. like Empatica Connect
    # diffs_x = pd.rolling_apply(acc_csv_stream['x'], 2, lambda x: abs(x[0] - x[1]))
    # diffs_y = pd.rolling_apply(acc_csv_stream['y'], 2, lambda x: abs(x[0] - x[1]))
    # diffs_z = pd.rolling_apply(acc_csv_stream['z'], 2, lambda x: abs(x[0] - x[1]))
    #
    # # diffs_x = diffs_x.drop(diffs_x.index[:1])
    # # diffs_y = diffs_y.drop(diffs_y.index[:1])
    # # diffs_z = diffs_z.drop(diffs_z.index[:1])
    #
    # combined = pd.concat([diffs_x, diffs_y, diffs_z], axis=1)
    # print combined
    # maxed = combined.apply(max, axis=1)
    # print 'maxed: ', maxed
    # averaged = pd.rolling_sum(maxed, 1)

    acc_csv_stream **= 2
    acc_csv_stream = acc_csv_stream.apply(sum, axis=1)
    acc_csv_stream **= 0.5
    acc_csv_stream = acc_csv_stream.to_frame()
    acc_csv_stream.set_index(index_acc, inplace=True)
    print acc_csv_stream
    return acc_csv_stream


def read_bvp(path, side):
    bvp_filepath = path + side + '/BVP.csv'

    # read bvp file
    print('Start Reading BVP file')
    bvp_csv_stream = pd.read_csv(bvp_filepath, header=None, names=[side + ' bvp'])
    bvp_csv_initial_timestamp = dt.utcfromtimestamp(bvp_csv_stream.ix[0, side + ' bvp'])
    bvp_csv_initial_timestamp = bvp_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    bvp_csv_initial_timestamp = bvp_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    bvp_csv_stream = bvp_csv_stream.drop(bvp_csv_stream.index[:2])
    index_bvp = pd.date_range(start=bvp_csv_initial_timestamp, periods=len(bvp_csv_stream.index), freq='15625U')
    bvp_csv_stream.set_index(index_bvp, inplace=True)

    return bvp_csv_stream


def read_breathing_waveform(path):
    breathing_path = path + 'bio/summary.csv'
    breathing_csv_stream = pd.read_csv(breathing_path, header=None, usecols=[0,2])
    hr_csv_stream = pd.read_csv(breathing_path, header=None, usecols=[1])
    s = breathing_csv_stream.ix[1][0]
    s = s.split('.')
    t = time.mktime(dt.strptime(s[0], "%d/%m/%Y %H:%M:%S").timetuple())
    breathing_csv_initial_timestamp = dt.utcfromtimestamp(t) + datetime.timedelta(hours=BREATHING_HOURS_OFFSET[path], milliseconds=int(s[1]))
    breathing_csv_initial_timestamp = breathing_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    breathing_csv_initial_timestamp = breathing_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))

    breathing_csv_stream = breathing_csv_stream.drop(breathing_csv_stream.index[:1])
    index_breathing = pd.date_range(start=breathing_csv_initial_timestamp, periods=len(breathing_csv_stream.index), freq='1000000U')
    breathing_csv_stream[2] = pd.to_numeric(breathing_csv_stream[2])
    breathing_csv_stream.set_index(index_breathing, inplace=True)

    hr_csv_stream = hr_csv_stream.drop(hr_csv_stream.index[:1])
    hr_csv_stream[1] = pd.to_numeric(hr_csv_stream[1])
    hr_csv_stream.set_index(index_breathing, inplace=True)

    return breathing_csv_stream, hr_csv_stream


f3984e6ae25d5fbf381d8e51a35c50b34bda5904
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404

import math
import pandas as pd
from datetime import datetime as dt
import datetime
from dateutil import tz
import pandas_highcharts.core
import time

from graphs.models import Participants, Graphs


PATH_MAP = ['practice/greg/', 'practice/landon/', 'practice/thomas1/', 'practice/thomas2/', 'practice/jesus/',
            'practice/dylan/', 'practice/ivy/', 'practice/william/', 'practice/dominic/', 'match/greg/',
            'match/landon/', 'match/dylan/', 'match/william/']

SHOT_MARKERS = {
    'practice': {
        'greg': [(1510786161000, 9.3, 'green', 0.66847800000000002), (1510786188000, 10.0, 'green', 0.68895899999999999), (1510786232000, 9.3, 'green', 0.744004), (1510786284000, 9.5, 'green', 0.815689), (1510786317000, 9.8, 'green', 0.81312899999999999), (1510786345000, 9.0, 'green', 0.85281200000000013), (1510786462000, 9.8, 'green', 1.012893), (1510786494000, 9.6, 'green', 1.066657), (1510786674000, 10.0, 'green', 1.4610259999999999), (1510786702000, 9.3, 'green', 1.5826360000000002), (1510786744000, 10.5, 'green', 1.6658419999999998), (1510786810000, 10.5, 'green', 1.6402400000000001), (1510786845000, 9.0, 'green', 1.704245), (1510786931000, 10.3, 'green', 1.535272), (1510787009000, 9.7, 'green', 2.1703999999999999), (1510787048000, 10.6, 'green', 2.1102349999999999), (1510787098000, 8.6, 'gold', 2.6195400000000002), (1510787128000, 9.9, 'green', 2.884125), (1510787170000, 10.0, 'green', 3.2617529999999997), (1510787214000, 8.7, 'gold', 3.4040300000000001), (1510787275000, 10.3, 'green', 3.679853), (1510787327000, 9.7, 'green', 4.0459610000000001), (1510787420000, 9.9, 'green', 3.3948830000000001), (1510787937000, 9.4, 'green', 1.741368), (1510787983000, 10.2, 'green', 1.828414), (1510788030000, 10.1, 'green', 1.7631290000000002), (1510788072000, 9.1, 'green', 1.9924660000000001), (1510788117000, 9.7, 'green', 2.0910330000000004), (1510788165000, 9.8, 'green', 2.2318439999999997), (1510788209000, 10.7, 'green', 2.909726), (1510788268000, 10.0, 'green', 4.0805239999999996), (1510788303000, 10.0, 'green', 4.0382800000000003), (1510788410000, 9.6, 'green', 4.4266079999999999), (1510788441000, 10.5, 'green', 5.0290650000000001), (1510788478000, 10.6, 'green', 4.7180010000000001), (1510788526000, 9.7, 'green', 4.9906620000000004), (1510788579000, 9.1, 'green', 5.5274390000000002), (1510788621000, 10.2, 'green', 5.4531929999999997), (1510788670000, 9.4, 'green', 5.5210379999999999), (1510788783000, 8.2, 'gold', 5.2991660000000005), (1510789660000, 9.8, 'green', 1.3892420000000001), (1510789695000, 10.5, 'green', 1.435424), (1510789725000, 9.6, 'green', 1.51223), (1510789759000, 9.5, 'green', 1.7068049999999999), (1510789798000, 9.1, 'green', 1.9361419999999998), (1510789832000, 10.0, 'green', 2.5939380000000001), (1510789861000, 10.2, 'green', 2.793237), (1510789905000, 9.7, 'green', 3.7016150000000003), (1510789952000, 8.6, 'gold', 4.3352629999999994), (1510789989000, 10.3, 'green', 4.292198), (1510790034000, 10.5, 'green', 4.8178489999999998), (1510790096000, 9.3, 'green', 4.1701309999999996), (1510790165000, 9.1, 'green', 4.3327029999999995), (1510790196000, 10.2, 'green', 5.1519550000000001), (1510790219000, 10.1, 'green', 4.8524120000000002), (1510790260000, 8.4, 'gold', 5.1276330000000003), (1510790297000, 9.6, 'green', 5.1293280000000001), (1510790328000, 9.8, 'green', 4.5827800000000005), (1510790372000, 9.9, 'green', 5.3507850000000001), (1510790419000, 10.0, 'green', 0.0)],
        'thomas1': [(1510786205000, 9.8, 'green', 1.3212489999999999), (1510786247000, 9.8, 'green', 1.3942709999999998), (1510786289000, 6.8, 'red', 2.8535599999999999), (1510786317000, 10.1, 'green', 2.5525009999999999), (1510786478000, 8.2, 'gold', 3.3788110000000002), (1510786511000, 8.1, 'gold', 2.3573720000000002), (1510786697000, 8.5, 'gold', 2.8702139999999998), (1510786745000, 9.6, 'green', 3.0743480000000001), (1510786849000, 10.1, 'green', 3.5624470000000001), (1510786894000, 8.9, 'gold', 3.9912489999999998), (1510786968000, 8.4, 'gold', 5.0501480000000001), (1510787262000, 10.8, 'green', 2.0499080000000003), (1510787330000, 9.7, 'green', 3.1371220000000002), (1510787379000, 7.2, 'red', 4.3204910000000005), (1510787436000, 9.2, 'green', 4.6535769999999994), (1510787473000, 9.9, 'green', 5.0142769999999999), (1510787496000, 10.4, 'green', 5.1628850000000002), (1510787527000, 9.7, 'green', 4.6683810000000001), (1510787571000, 10.8, 'green', 5.272729), (1510787598000, 10.6, 'green', 5.7603150000000003), (1510787710000, 10.2, 'green', 6.9545630000000003), (1510787747000, 10.4, 'green', 6.4170870000000004), (1510787789000, 8.4, 'gold', 6.6656199999999997), (1510787813000, 9.3, 'green', 6.8418259999999993), (1510787847000, 9.6, 'green', 7.0416780000000001), (1510787880000, 10.2, 'green', 6.9058809999999999), (1510787981000, 10.3, 'green', 6.9174110000000004), (1510788080000, 9.1, 'green', 6.8846880000000006), (1510788099000, 8.1, 'gold', 6.5592889999999997), (1510788118000, 10.3, 'green', 6.8385690000000006), (1510788512000, 10.8, 'green', 2.665238), (1510788618000, 9.5, 'green', 3.8071370000000004), (1510788747000, 9.8, 'green', 4.4498819999999997), (1510788775000, 10.0, 'green', 3.8698309999999996), (1510788826000, 7.3, 'red', 5.0719269999999996), (1510788855000, 9.8, 'green', 4.526179), (1510788904000, 9.1, 'green', 5.3214110000000003), (1510788935000, 8.9, 'gold', 5.1817710000000003), (1510788960000, 10.8, 'green', 5.0587849999999994), (1510788982000, 9.6, 'green', 6.0613730000000006), (1510789008000, 8.0, 'gold', 5.8897059999999994), (1510789057000, 9.2, 'green', 6.0895570000000001), (1510789116000, 9.8, 'green', 5.6360480000000006), (1510789172000, 9.7, 'green', 5.9985989999999996), (1510789192000, 9.8, 'green', 6.1062120000000002), (1510789761000, 8.9, 'gold', 1.5469219999999999), (1510789784000, 9.5, 'green', 1.573825), (1510789812000, 9.7, 'green', 1.423737), (1510789860000, 9.7, 'green', 1.9415), (1510789907000, 9.4, 'green', 2.944518), (1510789939000, 9.7, 'green', 3.1213099999999998), (1510789973000, 9.9, 'green', 3.2396099999999999), (1510790015000, 8.4, 'gold', 4.8957050000000004), (1510790035000, 8.9, 'gold', 4.448601), (1510790093000, 10.4, 'green', 3.9018589999999995), (1510790178000, 8.6, 'gold', 4.3076800000000004), (1510790196000, 9.7, 'green', 4.3397079999999999), (1510790216000, 8.5, 'gold', 4.2333769999999999), (1510790237000, 10.4, 'green', 5.4815480000000001), (1510790260000, 9.7, 'green', 5.4994839999999998)],
        'thomas2': [(1510873135000, 9.3, 'green', 2.8303599999999998), (1510873223000, 10.1, 'green', 3.4123129999999997), (1510873252000, 9.8, 'green', 3.023841), (1510873284000, 7.7, 'red', 2.5576989999999999), (1510873307000, 9.6, 'green', 2.9174069999999999), (1510873335000, 8.8, 'gold', 3.8731480000000005), (1510873354000, 9.1, 'green', 3.003174), (1510873375000, 9.9, 'green', 3.6260889999999999), (1510873402000, 9.1, 'green', 3.9141110000000001), (1510873421000, 9.1, 'green', 3.9537940000000003), (1510873648000, 9.9, 'green', 1.8631759999999999), (1510873688000, 9.5, 'green', 2.1332770000000001), (1510873718000, 9.2, 'green', 2.2956750000000001), (1510873744000, 10.2, 'green', 2.4620880000000001), (1510873791000, 9.4, 'green', 3.076139), (1510873880000, 8.9, 'gold', 4.1897900000000003), (1510873901000, 10.4, 'green', 5.3853480000000005), (1510873929000, 9.1, 'green', 4.9245130000000001), (1510873967000, 8.6, 'gold', 5.0073040000000004), (1510873988000, 9.9, 'green', 4.8511309999999996), (1510874042000, 10.1, 'green', 4.3613230000000005), (1510874095000, 9.5, 'green', 4.5720700000000001), (1510874125000, 10.0, 'green', 4.4931730000000005), (1510874197000, 10.0, 'green', 4.1731489999999996), (1510874301000, 9.6, 'green', 3.5851260000000003), (1510874335000, 10.1, 'green', 3.8232239999999997), (1510874369000, 9.5, 'green', 4.8413059999999994), (1510874399000, 8.5, 'gold', 4.4402200000000001), (1510874424000, 9.5, 'green', 4.4150870000000006), (1510874446000, 10.5, 'green', 3.8104230000000001), (1510874782000, 9.9, 'green', 1.5329110000000001), (1510874807000, 9.4, 'green', 1.436704), (1510874826000, 10.2, 'green', 1.5147899999999999), (1510874893000, 8.8, 'gold', 2.271353), (1510874922000, 10.6, 'green', 2.076778), (1510874954000, 10.2, 'green', 2.2649529999999998), (1510874977000, 8.2, 'gold', 3.1300889999999999), (1510875005000, 8.7, 'gold', 3.3400249999999998), (1510875028000, 10.2, 'green', 3.6184080000000001), (1510875055000, 9.4, 'green', 3.812983), (1510875079000, 10.3, 'green', 3.3937889999999999), (1510875125000, 8.6, 'gold', 3.7016150000000003), (1510875173000, 9.5, 'green', 3.7387379999999997), (1510875194000, 7.0, 'red', 4.0741230000000002), (1510875251000, 10.2, 'green', 3.7604989999999998), (1510875280000, 8.0, 'gold', 4.3096610000000002), (1510875321000, 9.4, 'green', 4.287077), (1510875365000, 10.6, 'green', 4.6839079999999997), (1510875393000, 8.1, 'gold', 5.1472499999999997), (1510875414000, 8.8, 'gold', 4.709041), (1510875680000, 9.4, 'green', 2.3763209999999999), (1510875701000, 10.0, 'green', 2.35968), (1510875727000, 9.1, 'green', 2.208628), (1510875754000, 9.7, 'green', 2.3059159999999999), (1510875776000, 10.9, 'green', 2.2495919999999998), (1510875807000, 9.2, 'green', 2.2495919999999998), (1510875836000, 9.9, 'green', 2.2214290000000001), (1510875857000, 10.3, 'green', 2.1203020000000001), (1510875884000, 10.0, 'green', 2.5644960000000001), (1510875914000, 9.7, 'green', 3.4827180000000002)],
        'landon': [(1510873096000, 8.8, 'gold', 6.4584730000000006), (1510873132000, 9.7, 'green', 5.7103109999999999), (1510873179000, 5.4, 'red', 5.9710660000000004), (1510873205000, 7.1, 'red', 5.9595370000000001), (1510873234000, 8.5, 'gold', 5.6872509999999998), (1510873280000, 9.2, 'green', 6.4783819999999999), (1510873310000, 8.2, 'gold', 5.9672230000000006), (1510873336000, 8.9, 'gold', 6.0613320000000002), (1510873379000, 10.0, 'green', 5.8832599999999999), (1510873470000, 8.8, 'gold', 5.2739150000000006), (1510873518000, 10.5, 'green', 5.7756470000000002), (1510873542000, 8.9, 'gold', 5.9473150000000006), (1510873583000, 7.7, 'red', 5.37256), (1510873635000, 9.5, 'green', 5.0785599999999995), (1510873697000, 10.0, 'green', 5.733371), (1510873731000, 7.7, 'red', 5.3610300000000004), (1510873784000, 9.5, 'green', 5.6018759999999999), (1510873838000, 9.0, 'green', 5.4899620000000002), (1510874077000, 9.1, 'green', 4.58108), (1510874129000, 8.5, 'gold', 5.053566), (1510874180000, 9.5, 'green', 5.1509289999999996), (1510874236000, 9.9, 'green', 4.967104), (1510874291000, 7.9, 'red', 5.1880809999999995), (1510874323000, 9.7, 'green', 5.1528640000000001), (1510874351000, 8.7, 'gold', 4.4777250000000004), (1510874396000, 10.1, 'green', 5.3610300000000004), (1510874431000, 9.4, 'green', 5.5519129999999999), (1510874464000, 10.6, 'green', 5.9798010000000001), (1510874505000, 9.8, 'green', 5.8491290000000005), (1510874547000, 10.6, 'green', 5.0510029999999997), (1510874598000, 8.5, 'gold', 4.6980729999999999), (1510874658000, 10.1, 'green', 4.6519539999999999), (1510874702000, 9.3, 'green', 4.9799160000000002), (1510874745000, 10.2, 'green', 5.8102369999999999), (1510874773000, 10.3, 'green', 5.8491290000000005), (1510874801000, 7.2, 'red', 5.0369109999999999), (1510874845000, 9.9, 'green', 5.1419620000000004), (1510874893000, 8.1, 'gold', 5.4680140000000002), (1510874933000, 9.1, 'green', 5.1522100000000002), (1510875177000, 10.3, 'green', 4.1775339999999996), (1510875277000, 9.8, 'green', 5.1932049999999998), (1510875340000, 10.0, 'green', 4.9286709999999996), (1510875374000, 9.3, 'green', 4.8889580000000006), (1510875411000, 8.8, 'gold', 4.8799900000000003), (1510875447000, 8.4, 'gold', 4.6686079999999999), (1510875473000, 9.2, 'green', 4.9709479999999999), (1510875504000, 9.3, 'green', 4.6135209999999995), (1510875535000, 8.4, 'gold', 4.9927260000000002), (1510875567000, 10.2, 'green', 4.3312660000000003), (1510875650000, 10.4, 'green', 5.1426150000000002), (1510876072000, 9.4, 'green', 3.292735), (1510876141000, 10.9, 'green', 3.4631220000000003), (1510876194000, 9.2, 'green', 4.0153540000000003), (1510876233000, 7.2, 'red', 3.866746), (1510876276000, 10.7, 'green', 4.2608050000000004), (1510876340000, 9.8, 'green', 3.9333629999999999), (1510876443000, 7.6, 'red', 5.2444499999999996), (1510876570000, 9.0, 'green', 4.9568560000000002), (1510876629000, 9.8, 'green', 4.9760720000000003), (1510876666000, 8.4, 'gold', 5.6505580000000002)],
        'dylan': [(1510873069000, 10.7, 'green', 1.5710729999999999), (1510873090000, 10.1, 'green', 1.692763), (1510873110000, 10.0, 'green', 1.618468), (1510873148000, 9.4, 'green', 1.7196630000000002), (1510873174000, 10.7, 'green', 2.3883160000000001), (1510873210000, 8.4, 'gold', 2.3017189999999998), (1510873237000, 8.7, 'gold', 2.5092319999999999), (1510873258000, 8.6, 'gold', 2.4362180000000002), (1510873294000, 8.7, 'gold', 2.75081), (1510873333000, 9.6, 'green', 2.3029999999999999), (1510873384000, 10.1, 'green', 2.4310939999999999), (1510873432000, 10.5, 'green', 2.0865200000000002), (1510873458000, 9.9, 'green', 2.1313529999999998), (1510873477000, 9.7, 'green', 2.1134200000000001), (1510873523000, 9.9, 'green', 2.1928389999999998), (1510873546000, 9.8, 'green', 2.2223000000000002), (1510873568000, 10.1, 'green', 2.2965949999999999), (1510873591000, 10.4, 'green', 2.3094049999999999), (1510873614000, 9.8, 'green', 2.6534580000000001), (1510873635000, 10.6, 'green', 2.332462), (1510873682000, 9.0, 'green', 2.352957), (1510873707000, 10.5, 'green', 2.2927520000000001), (1510873732000, 10.6, 'green', 2.282505), (1510873750000, 10.8, 'green', 2.6219549999999998), (1510873768000, 10.1, 'green', 2.687284), (1510873787000, 8.6, 'gold', 2.42469), (1510873810000, 9.6, 'green', 2.438259), (1510873831000, 8.7, 'gold', 2.5612300000000001), (1510873862000, 9.1, 'green', 2.7123819999999998), (1510873911000, 10.2, 'green', 2.8468810000000002), (1510873931000, 10.5, 'green', 3.3416309999999996), (1510873949000, 10.4, 'green', 2.921176), (1510873967000, 7.6, 'red', 2.977843), (1510874002000, 9.4, 'green', 2.7687430000000002), (1510874019000, 9.8, 'green', 2.73672), (1510874061000, 8.1, 'gold', 2.822543), (1510874080000, 9.6, 'green', 2.7892380000000001), (1510874103000, 10.0, 'green', 3.0262130000000003), (1510874126000, 9.5, 'green', 2.9070849999999999), (1510874146000, 8.9, 'gold', 3.3544410000000005), (1510874178000, 8.4, 'gold', 3.8335140000000001), (1510874201000, 9.4, 'green', 3.3326639999999998), (1510874248000, 9.3, 'green', 3.2814269999999999), (1510874272000, 8.9, 'gold', 3.0380470000000002), (1510874821000, 9.6, 'green', 1.078991), (1510874853000, 9.3, 'green', 1.0264719999999998), (1510874882000, 9.5, 'green', 2.1692749999999998), (1510874901000, 7.0, 'red', 1.957919), (1510874917000, 9.8, 'green', 1.9438279999999999), (1510874932000, 9.6, 'green', 1.6837959999999998), (1510874958000, 10.7, 'green', 1.7311909999999999), (1510874977000, 9.1, 'green', 2.3516759999999999), (1510875000000, 10.3, 'green', 2.0744849999999997), (1510875018000, 8.8, 'gold', 2.2812240000000004), (1510875041000, 10.3, 'green', 2.1031720000000003), (1510875069000, 9.2, 'green', 2.0527090000000001), (1510875087000, 10.4, 'green', 2.310686), (1510875102000, 9.6, 'green', 2.6406490000000002), (1510875114000, 8.0, 'gold', 2.6713909999999998), (1510875128000, 8.6, 'gold', 2.3209330000000001)],
        'ivy': [(1510873129000, 10.4, 'green', 9.2455879999999997), (1510873193000, 9.6, 'green', 9.5012070000000008), (1510873220000, 8.6, 'gold', 9.3481059999999996), (1510873279000, 7.5, 'red', 8.5729070000000007), (1510873363000, 9.3, 'green', 7.7069589999999994), (1510873401000, 8.5, 'gold', 8.8009130000000013), (1510873534000, 8.9, 'gold', 7.5941880000000008), (1510873639000, 7.2, 'red', 7.9629199999999996), (1510873798000, 8.8, 'gold', 7.8003720000000003), (1510873867000, 9.4, 'green', 7.1371649999999995), (1510873915000, 9.2, 'green', 7.0628390000000003), (1510873957000, 8.6, 'gold', 7.136698), (1510874023000, 8.6, 'gold', 7.2058979999999995), (1510874153000, 9.7, 'green', 7.0538690000000006), (1510874179000, 10.3, 'green', 5.7998640000000004), (1510874212000, 8.6, 'gold', 6.5841330000000005), (1510874244000, 9.1, 'green', 6.8814369999999991), (1510874275000, 9.7, 'green', 6.7955779999999999), (1510874308000, 9.3, 'green', 7.4122170000000001), (1510874405000, 10.3, 'green', 6.7386229999999996), (1510874538000, 9.8, 'green', 6.9616020000000001), (1510874564000, 9.2, 'green', 7.0782169999999995), (1510874675000, 9.4, 'green', 6.2233429999999998), (1510874757000, 10.3, 'green', 6.6533329999999999), (1510874933000, 8.9, 'gold', 6.4918659999999999), (1510875019000, 9.8, 'green', 5.8239780000000003), (1510875357000, 8.5, 'gold', 4.6917989999999996), (1510875438000, 9.7, 'green', 3.8794440000000003), (1510875473000, 10.2, 'green', 4.5722069999999997), (1510875707000, 9.4, 'green', 3.1412299999999997), (1510875742000, 10.5, 'green', 2.9628459999999999), (1510875777000, 10.3, 'green', 3.4321269999999995), (1510875961000, 10.5, 'green', 2.3464509999999996), (1510876032000, 8.9, 'gold', 3.4910760000000001), (1510876065000, 9.2, 'green', 3.1448160000000001), (1510876098000, 9.7, 'green', 2.9795050000000001), (1510876305000, 10.7, 'green', 2.8321339999999999), (1510876371000, 9.8, 'green', 2.7257709999999999), (1510876463000, 8.9, 'gold', 2.274489), (1510876498000, 10.3, 'green', 3.0126249999999999), (1510876531000, 10.3, 'green', 2.5961419999999999), (1510876561000, 10.0, 'green', 2.5359119999999997), (1510876621000, 8.0, 'gold', 2.7512020000000001), (1510876656000, 8.2, 'gold', 2.9141490000000001), (1510876681000, 10.3, 'green', 2.526942), (1510876704000, 9.2, 'green', 2.2719259999999997), (1510876735000, 10.2, 'green', 2.2475779999999999), (1510876805000, 10.3, 'green', 2.4910600000000001), (1510876896000, 10.4, 'green', 1.7921509999999998), (1510876962000, 9.3, 'green', 1.5512319999999999), (1510877027000, 9.7, 'green', 1.6268389999999999), (1510877050000, 10.8, 'green', 1.981811), (1510877076000, 8.5, 'gold', 2.1463410000000001), (1510877184000, 7.4, 'red', 1.9669330000000003), (1510877300000, 10.4, 'green', 1.761395), (1510877391000, 8.3, 'gold', 1.647343), (1510877430000, 8.4, 'gold', 1.5254030000000001), (1510877466000, 9.9, 'green', 1.8164990000000001), (1510877504000, 7.7, 'red', 2.0164110000000002), (1510877538000, 9.4, 'green', 2.279115)],
        'jesus': [(1510873156000, 9.7, 'green', 17.414789000000003), (1510873221000, 8.2, 'gold', 18.771377999999999), (1510873298000, 8.6, 'gold', 18.302965), (1510873326000, 9.9, 'green', 18.775879), (1510873384000, 9.1, 'green', 18.740009000000001), (1510873429000, 8.4, 'gold', 18.928944000000001), (1510873509000, 10.0, 'green', 18.413132000000001), (1510873532000, 8.7, 'gold', 18.397760000000002), (1510873557000, 10.2, 'green', 18.474838000000002), (1510873579000, 10.7, 'green', 18.190235000000001), (1510873606000, 8.0, 'gold', 18.304245000000002), (1510873631000, 10.1, 'green', 17.604382000000001), (1510873657000, 9.6, 'green', 17.864429000000001), (1510873685000, 10.6, 'green', 17.204681000000001), (1510873718000, 8.3, 'gold', 17.910973000000002), (1510873740000, 9.0, 'green', 17.170093999999999), (1510873768000, 9.2, 'green', 16.627476000000001), (1510873796000, 9.5, 'green', 16.733264999999999), (1510873826000, 9.8, 'green', 18.425943), (1510873853000, 9.9, 'green', 18.33905), (1510874307000, 9.9, 'green', 8.5883369999999992), (1510874375000, 10.2, 'green', 11.291917999999999), (1510874419000, 10.4, 'green', 10.12102), (1510874445000, 9.7, 'green', 10.83203), (1510874508000, 10.2, 'green', 10.156889), (1510874531000, 8.8, 'gold', 9.8243840000000002), (1510874557000, 8.3, 'gold', 9.3465619999999987), (1510874585000, 9.0, 'green', 9.3183799999999994), (1510874613000, 9.4, 'green', 8.9956420000000001), (1510874642000, 8.7, 'gold', 9.7718619999999987), (1510874667000, 10.1, 'green', 10.109491), (1510874715000, 8.5, 'gold', 9.4618549999999999), (1510874737000, 10.1, 'green', 9.5797880000000006), (1510874770000, 10.3, 'green', 9.9147759999999998), (1510874815000, 9.7, 'green', 9.8929989999999997), (1510874847000, 10.4, 'green', 9.3888369999999988), (1510874870000, 10.5, 'green', 8.9405579999999993), (1510874892000, 8.5, 'gold', 9.4747450000000004), (1510874914000, 9.6, 'green', 9.6918779999999991), (1510874930000, 9.4, 'green', 10.049844), (1510875561000, 8.4, 'gold', 3.5532660000000003), (1510875587000, 8.6, 'gold', 3.476404), (1510875611000, 10.0, 'green', 3.3021849999999997), (1510875634000, 10.3, 'green', 3.167678), (1510875660000, 9.9, 'green', 3.0301689999999999), (1510875683000, 9.1, 'green', 2.8444210000000001), (1510875705000, 8.8, 'gold', 2.69326), (1510875740000, 9.6, 'green', 2.6057480000000002), (1510875767000, 10.6, 'green', 2.6416169999999997), (1510875788000, 10.4, 'green', 2.5173580000000002), (1510875805000, 10.2, 'green', 2.5596320000000001), (1510875828000, 9.2, 'green', 2.8085520000000002), (1510875855000, 9.3, 'green', 3.15699), (1510875877000, 10.6, 'green', 3.5801669999999999), (1510875898000, 9.1, 'green', 4.4342420000000002), (1510875922000, 10.3, 'green', 5.134061), (1510875947000, 10.1, 'green', 5.1407970000000001), (1510875973000, 9.3, 'green', 5.5837000000000003), (1510875996000, 10.4, 'green', 5.8944749999999999), (1510876014000, 9.3, 'green', 6.5857960000000002)],
        'william': [(1510959725000, 9.0, 'green', 1.1994), (1510959766000, 9.9, 'green', 2.0852390000000001), (1510959949000, 9.1, 'green', 2.8148569999999999), (1510959981000, 9.2, 'green', 2.4772080000000001), (1510960087000, 9.0, 'green', 2.7175050000000001), (1510960119000, 10.2, 'green', 2.6124680000000002), (1510960199000, 9.1, 'green', 2.5612300000000001), (1510960230000, 9.7, 'green', 2.4848939999999997), (1510960388000, 9.3, 'green', 2.8122950000000002), (1510960453000, 10.0, 'green', 2.4208470000000002), (1510960490000, 10.7, 'green', 2.4964230000000001), (1510960552000, 8.8, 'gold', 2.7777099999999999), (1510960609000, 10.3, 'green', 2.7456860000000001), (1510960665000, 9.5, 'green', 2.474126), (1510960696000, 9.1, 'green', 2.9467950000000003), (1510960733000, 8.9, 'gold', 2.4848939999999997), (1510960796000, 9.1, 'green', 2.8750619999999998), (1510960825000, 8.8, 'gold', 2.4433830000000003), (1510960852000, 10.4, 'green', 2.4144419999999998), (1510960879000, 8.8, 'gold', 2.1953999999999998), (1510960905000, 10.2, 'green', 2.4989849999999998), (1510960940000, 8.6, 'gold', 2.8904330000000003), (1510960966000, 8.8, 'gold', 2.6573009999999999), (1510961024000, 10.0, 'green', 2.5246029999999999), (1510961058000, 9.0, 'green', 2.1813099999999999), (1510961205000, 8.8, 'gold', 2.232548), (1510961230000, 10.7, 'green', 2.4195660000000001), (1510961286000, 9.4, 'green', 2.2671330000000003), (1510961318000, 8.7, 'gold', 3.7938050000000003), (1510961345000, 8.9, 'gold', 2.6893250000000002), (1510961510000, 8.4, 'gold', 1.8321869999999998), (1510961551000, 9.0, 'green', 1.7233060000000002), (1510961623000, 7.9, 'red', 1.749125), (1510962016000, 9.7, 'green', 1.488893), (1510962167000, 7.4, 'red', 2.6662669999999999), (1510962561000, 10.1, 'green', 0.59334500000000001), (1510962621000, 9.5, 'green', 0.63049200000000005), (1510962657000, 9.9, 'green', 0.55875900000000001), (1510962681000, 9.1, 'green', 0.54210700000000001), (1510962744000, 8.6, 'gold', 0.69710099999999997), (1510962809000, 8.0, 'gold', 1.0098200000000002), (1510962836000, 8.4, 'gold', 1.4878120000000001), (1510962864000, 8.3, 'gold', 1.7220259999999998), (1510962922000, 9.6, 'green', 1.501703), (1510962987000, 8.6, 'gold', 1.7245869999999999), (1510963019000, 7.6, 'red', 1.461994), (1510963055000, 10.0, 'green', 1.039183), (1510963092000, 8.8, 'gold', 1.0097209999999999), (1510963120000, 9.9, 'green', 1.5426930000000001), (1510963153000, 9.4, 'green', 1.103329), (1510963264000, 8.8, 'gold', 0.70741799999999999), (1510963325000, 8.3, 'gold', 1.2351669999999999), (1510963350000, 8.5, 'gold', 0.89827900000000005), (1510963368000, 9.0, 'green', 1.099486), (1510963395000, 7.7, 'red', 1.6733499999999999), (1510963416000, 9.0, 'green', 1.140476), (1510963439000, 9.8, 'green', 1.355675), (1510963477000, 10.5, 'green', 1.0712059999999999), (1510963498000, 9.9, 'green', 1.039183), (1510963515000, 10.8, 'green', 0.90212099999999995)],
        'dominic': [(1510959364000, 7.4, 'red', 2.2963040000000001), (1510959396000, 6.5, 'red', 2.976086), (1510959441000, 9.7, 'green', 3.6011870000000004), (1510959483000, 7.6, 'red', 4.3122540000000003), (1510959529000, 9.7, 'green', 4.2635779999999999), (1510959562000, 10.2, 'green', 4.7497290000000003), (1510959590000, 3.9, 'red', 4.9777370000000003), (1510959627000, 8.7, 'gold', 5.3757349999999997), (1510959666000, 10.4, 'green', 5.681152), (1510959702000, 7.2, 'red', 5.4390540000000005), (1510959742000, 6.8, 'red', 5.3706110000000002), (1510959794000, 8.3, 'gold', 5.2899120000000002), (1510959840000, 7.9, 'red', 5.8976319999999998), (1510959866000, 7.3, 'red', 5.799728), (1510959905000, 9.5, 'green', 5.8899460000000001), (1510959942000, 7.7, 'red', 5.2578879999999995), (1510959994000, 9.7, 'green', 5.3142500000000004), (1510960025000, 10.3, 'green', 5.1336360000000001), (1510960051000, 9.5, 'green', 5.2258639999999996), (1510960079000, 7.0, 'red', 5.1784699999999999), (1510960401000, 8.1, 'gold', 3.8428960000000001), (1510960440000, 9.8, 'green', 3.4538790000000001), (1510960489000, 10.4, 'green', 3.052943), (1510960535000, 9.1, 'green', 2.9927380000000001), (1510960580000, 9.0, 'green', 2.9012029999999998), (1510960627000, 10.4, 'green', 2.892236), (1510960680000, 9.9, 'green', 2.7743889999999998), (1510960729000, 9.6, 'green', 2.4628269999999999), (1510960777000, 10.3, 'green', 3.0004240000000002), (1510960804000, 10.4, 'green', 2.6988129999999999), (1510960899000, 8.8, 'gold', 2.4269609999999999), (1510960947000, 7.5, 'red', 3.7429830000000002), (1510961005000, 9.2, 'green', 5.2134309999999999), (1510961050000, 6.8, 'red', 4.9495569999999995), (1510961092000, 9.8, 'green', 4.3596490000000001), (1510961148000, 9.2, 'green', 4.6357249999999999), (1510961195000, 9.0, 'green', 4.7561339999999994), (1510961241000, 9.5, 'green', 4.4236959999999996), (1510961278000, 7.0, 'red', 4.5486209999999998), (1510961318000, 8.0, 'gold', 4.4794499999999999), (1510961692000, 8.0, 'gold', 4.3109730000000006), (1510961736000, 10.0, 'green', 4.2822610000000001), (1510961778000, 10.5, 'green', 3.6434589999999996), (1510961819000, 8.9, 'gold', 4.0944929999999999), (1510961860000, 10.8, 'green', 4.0388809999999999), (1510961904000, 10.0, 'green', 3.8633919999999997), (1510961935000, 10.4, 'green', 4.6177919999999997), (1510961964000, 9.2, 'green', 6.637594), (1510961991000, 9.2, 'green', 4.6344440000000002), (1510962040000, 9.2, 'green', 4.3558059999999994), (1510962352000, 9.7, 'green', 4.7766289999999998), (1510962386000, 8.8, 'gold', 4.9828609999999998), (1510962430000, 8.9, 'gold', 4.8970379999999993), (1510962469000, 9.1, 'green', 4.407044), (1510962511000, 9.0, 'green', 4.772786), (1510962541000, 10.0, 'green', 4.8278669999999995), (1510962565000, 8.4, 'gold', 5.2066499999999998), (1510962598000, 9.1, 'green', 4.7817530000000001), (1510962618000, 8.7, 'gold', 5.4000729999999999), (1510962646000, 8.5, 'gold', 5.6408910000000008)]
    },
    'match': {
        'dylan': [(1511038991000, 7.9, 'red', 2.6209549999999999), (1511039056000, 9.7, 'green', 2.578681), (1511039103000, 8.5, 'gold', 3.8389359999999999), (1511039131000, 8.3, 'gold', 3.725857), (1511039234000, 9.1, 'green', 4.271922), (1511039277000, 10.7, 'green', 4.7625539999999997), (1511039302000, 9.3, 'green', 4.6583050000000004), (1511039322000, 10.8, 'green', 4.6519000000000004), (1511039345000, 10.6, 'green', 4.5250789999999999), (1511039372000, 9.6, 'green', 4.6498239999999997), (1511039395000, 8.5, 'gold', 4.8056230000000006), (1511039422000, 10.1, 'green', 5.5497879999999995), (1511039445000, 9.9, 'green', 4.8517390000000002), (1511039479000, 9.8, 'green', 4.4679180000000001), (1511039507000, 9.5, 'green', 4.365437), (1511039530000, 8.8, 'gold', 4.6980170000000001), (1511039556000, 10.4, 'green', 4.4884149999999998), (1511039579000, 10.0, 'green', 4.4115529999999996), (1511039602000, 9.5, 'green', 4.8504589999999999), (1511039654000, 10.1, 'green', 4.7454150000000004), (1511039677000, 10.1, 'green', 5.0541410000000004), (1511039699000, 10.2, 'green', 4.5801629999999998), (1511039721000, 9.2, 'green', 5.0016189999999998), (1511039745000, 9.3, 'green', 4.6980170000000001), (1511039791000, 10.3, 'green', 4.9964949999999995), (1511039812000, 8.9, 'gold', 4.6877680000000002), (1511039836000, 10.0, 'green', 4.9490970000000001), (1511039863000, 9.7, 'green', 6.0993469999999999), (1511039891000, 8.2, 'gold', 4.7953739999999998), (1511039919000, 10.7, 'green', 5.0387690000000003), (1511039946000, 10.6, 'green', 4.962224), (1511039968000, 9.0, 'green', 5.023396), (1511039999000, 10.4, 'green', 5.1979329999999999), (1511040083000, 9.5, 'green', 5.6138389999999996), (1511040111000, 9.9, 'green', 5.2273959999999997), (1511040144000, 9.9, 'green', 5.7752480000000004), (1511040177000, 9.3, 'green', 5.0518960000000002), (1511040203000, 8.5, 'gold', 5.5036719999999999), (1511040226000, 10.1, 'green', 5.1569400000000005), (1511040252000, 8.3, 'gold', 5.3145059999999997), (1511040329000, 10.3, 'green', 5.0775169999999994), (1511040359000, 9.6, 'green', 5.1569400000000005), (1511040381000, 9.8, 'green', 5.0211519999999998), (1511040407000, 9.8, 'green', 5.4502940000000004), (1511040430000, 9.5, 'green', 5.8085550000000001), (1511040452000, 7.7, 'red', 5.3106629999999999), (1511040643000, 10.3, 'green', 4.3116339999999997), (1511040663000, 8.7, 'gold', 4.139977), (1511040684000, 9.4, 'green', 4.1233230000000001), (1511040706000, 7.5, 'red', 4.371842), (1511040727000, 10.7, 'green', 3.9952209999999999), (1511040761000, 10.2, 'green', 3.8526790000000002), (1511040784000, 9.2, 'green', 3.8731749999999998), (1511040800000, 9.9, 'green', 4.4379689999999998), (1511040817000, 9.7, 'green', 4.8094660000000005), (1511040834000, 9.8, 'green', 4.5699139999999998), (1511040856000, 7.9, 'red', 4.6621480000000002), (1511040878000, 9.9, 'green', 6.4939019999999994), (1511040898000, 10.1, 'green', 5.1723120000000007), (1511040915000, 9.0, 'green', 5.1441300000000005)],
        'william': [(1511039104000, 8.6, 'gold', 4.2768930000000003), (1511039255000, 9.2, 'green', 6.9809449999999993), (1511039483000, 8.6, 'gold', 8.2336650000000002), (1511039570000, 9.0, 'green', 8.6253250000000001), (1511039629000, 9.6, 'green', 9.3678710000000009), (1511039660000, 8.6, 'gold', 9.4306029999999996), (1511039704000, 10.4, 'green', 8.70214), (1511039765000, 8.9, 'gold', 8.6880570000000006), (1511039791000, 9.9, 'green', 8.7406439999999996), (1511039851000, 10.1, 'green', 8.9569100000000006), (1511039908000, 9.2, 'green', 7.8113089999999996), (1511039945000, 9.3, 'green', 8.6726939999999999), (1511040048000, 7.4, 'red', 10.626499000000001), (1511040134000, 8.9, 'gold', 11.537861999999999), (1511040432000, 9.6, 'green', 5.9642520000000001), (1511040491000, 9.6, 'green', 5.7914180000000002), (1511040513000, 9.6, 'green', 5.2042000000000002), (1511040638000, 10.5, 'green', 5.387276), (1511040665000, 10.7, 'green', 5.517862), (1511040781000, 9.4, 'green', 5.2592509999999999), (1511040812000, 10.4, 'green', 4.7044860000000002), (1511040863000, 9.7, 'green', 5.5127410000000001), (1511040895000, 9.1, 'green', 4.7825819999999997), (1511040934000, 9.7, 'green', 4.5065160000000004), (1511041194000, 10.4, 'green', 4.5334010000000005), (1511041280000, 9.6, 'green', 4.537242), (1511041360000, 9.5, 'green', 4.7390530000000002), (1511041380000, 10.7, 'green', 4.8017849999999997), (1511041433000, 10.1, 'green', 4.2299819999999997), (1511041535000, 9.9, 'green', 4.0673900000000005), (1511041566000, 9.6, 'green', 4.2555870000000002), (1511041642000, 10.1, 'green', 3.9888370000000002), (1511041667000, 9.4, 'green', 4.1680720000000004), (1511041691000, 10.2, 'green', 4.0246830000000005), (1511041709000, 10.5, 'green', 3.6905379999999997), (1511041758000, 10.0, 'green', 3.278975), (1511041781000, 10.8, 'green', 3.170153), (1511041825000, 9.6, 'green', 3.5145410000000004), (1511041853000, 9.3, 'green', 3.4863749999999998), (1511041891000, 9.9, 'green', 3.198318), (1511041993000, 9.8, 'green', 3.2456879999999999), (1511042074000, 10.0, 'green', 3.0434080000000003), (1511042158000, 9.9, 'green', 3.0739490000000003), (1511042205000, 10.4, 'green', 2.8166180000000001), (1511042229000, 9.6, 'green', 2.985611), (1511042276000, 10.3, 'green', 2.853745), (1511042334000, 9.3, 'green', 2.8742290000000001), (1511042354000, 10.1, 'green', 2.6706689999999997), (1511042520000, 10.4, 'green', 2.3382000000000001), (1511042630000, 6.8, 'red', 3.7647919999999999), (1511042728000, 9.1, 'green', 3.5644709999999997), (1511042750000, 10.6, 'green', 3.0856560000000002), (1511042773000, 9.3, 'green', 3.4710120000000004), (1511042797000, 8.4, 'gold', 3.2072799999999999), (1511042841000, 9.7, 'green', 3.7699129999999998), (1511042865000, 10.2, 'green', 3.9726510000000004), (1511042893000, 8.4, 'gold', 4.3362429999999996), (1511042939000, 9.7, 'green', 4.2376629999999995), (1511043022000, 8.7, 'gold', 3.9773139999999998), (1511043065000, 9.9, 'green', 4.443784)],
        'greg': [(1511038999000, 9.9, 'green', 0.61643900000000007), (1511039025000, 9.2, 'green', 0.62284399999999995), (1511039053000, 9.8, 'green', 0.62412500000000004), (1511039084000, 9.7, 'green', 0.62924899999999995), (1511039114000, 10.1, 'green', 0.63693500000000003), (1511039149000, 8.5, 'gold', 0.64333999999999991), (1511039190000, 9.7, 'green', 0.64974500000000002), (1511039226000, 10.0, 'green', 0.65230699999999997), (1511039255000, 9.0, 'green', 0.65743099999999999), (1511039288000, 9.3, 'green', 0.66383700000000001), (1511039321000, 9.6, 'green', 0.67536600000000002), (1511039357000, 10.7, 'green', 0.67536600000000002), (1511039395000, 10.4, 'green', 0.69842399999999993), (1511039430000, 10.3, 'green', 0.72148299999999999), (1511039468000, 9.9, 'green', 0.72916899999999996), (1511039497000, 9.7, 'green', 0.73685500000000004), (1511039530000, 9.3, 'green', 0.74197899999999994), (1511039578000, 10.4, 'green', 0.77784799999999998), (1511039601000, 9.0, 'green', 0.78681499999999993), (1511039634000, 9.6, 'green', 0.79193900000000006), (1511039693000, 10.1, 'green', 0.82140200000000008), (1511039733000, 10.7, 'green', 0.84317999999999993), (1511039768000, 9.1, 'green', 0.86239500000000002), (1511039805000, 10.2, 'green', 0.920041), (1511039839000, 10.7, 'green', 1.0173989999999999), (1511039874000, 8.6, 'gold', 1.073833), (1511039904000, 10.5, 'green', 1.0828), (1511039971000, 9.2, 'green', 1.3236319999999999), (1511040010000, 9.5, 'green', 1.553034), (1511040061000, 9.6, 'green', 1.8169249999999999), (1511040101000, 10.6, 'green', 1.8233299999999999), (1511040145000, 10.4, 'green', 1.7415439999999998), (1511040195000, 10.3, 'green', 1.8260909999999999), (1511040241000, 8.5, 'gold', 1.7722880000000001), (1511040288000, 9.7, 'green', 2.159157), (1511040331000, 10.4, 'green', 2.3059889999999998), (1511040373000, 8.2, 'gold', 2.659551), (1511040418000, 8.2, 'gold', 2.7748430000000002), (1511040460000, 9.3, 'green', 2.9417789999999999), (1511040500000, 10.1, 'green', 2.91872), (1511040854000, 9.8, 'green', 1.9336970000000002), (1511040891000, 10.3, 'green', 1.9388209999999999), (1511040962000, 9.7, 'green', 2.0669240000000002), (1511041015000, 8.1, 'gold', 2.408471), (1511041048000, 10.2, 'green', 2.5801279999999998), (1511041083000, 10.7, 'green', 2.5984639999999999), (1511041137000, 9.7, 'green', 2.6778880000000003), (1511041173000, 9.3, 'green', 2.7983039999999999), (1511041222000, 9.8, 'green', 3.28125), (1511041267000, 10.5, 'green', 3.3017460000000001), (1511041312000, 9.4, 'green', 3.312433), (1511041359000, 10.4, 'green', 3.4969010000000003), (1511041408000, 9.4, 'green', 3.7414959999999997), (1511041442000, 7.8, 'red', 4.0681570000000002), (1511041476000, 8.8, 'gold', 4.2923359999999997), (1511041544000, 9.6, 'green', 4.7660269999999993), (1511041579000, 10.7, 'green', 4.9563300000000003), (1511041623000, 9.9, 'green', 4.8115740000000002), (1511041663000, 10.6, 'green', 4.8333519999999996), (1511041695000, 10.6, 'green', 4.964016)],
        'landon': [(1511039024000, 8.8, 'gold', 13.181679999999998), (1511039046000, 7.2, 'red', 12.806363000000001), (1511039069000, 7.2, 'red', 13.035489999999999), (1511039099000, 8.6, 'gold', 13.058709), (1511039120000, 8.5, 'gold', 14.175804000000001), (1511039164000, 10.4, 'green', 13.298083999999999), (1511039197000, 10.6, 'green', 13.129), (1511039258000, 8.0, 'gold', 12.957514), (1511039281000, 10.3, 'green', 12.889625000000001), (1511039312000, 9.4, 'green', 12.789710000000001), (1511039342000, 9.4, 'green', 12.712396999999999), (1511039364000, 10.5, 'green', 12.462612), (1511039384000, 8.8, 'gold', 12.415217), (1511039411000, 10.2, 'green', 12.832806), (1511039433000, 10.5, 'green', 11.987052), (1511039455000, 9.1, 'green', 11.899948), (1511039486000, 9.2, 'green', 13.231636999999999), (1511039524000, 10.1, 'green', 12.712396999999999), (1511039556000, 7.9, 'red', 12.553559), (1511039582000, 7.4, 'red', 12.052710000000001), (1511039616000, 8.9, 'gold', 11.94478), (1511039649000, 8.8, 'gold', 12.255099000000001), (1511039674000, 9.8, 'green', 11.674066999999999), (1511039732000, 10.4, 'green', 11.607892), (1511039756000, 9.5, 'green', 12.762354), (1511039800000, 10.2, 'green', 11.500292999999999), (1511039881000, 7.4, 'red', 12.486950999999999), (1511039966000, 9.3, 'green', 10.600896000000001), (1511040030000, 9.0, 'green', 10.439827000000001), (1511040060000, 9.8, 'green', 11.634357000000001), (1511040281000, 10.2, 'green', 9.7177139999999991), (1511040305000, 10.3, 'green', 9.3822089999999996), (1511040443000, 7.2, 'red', 8.8673320000000011), (1511040506000, 9.4, 'green', 9.1759769999999996), (1511040591000, 7.9, 'red', 10.862209), (1511040681000, 9.2, 'green', 8.8314649999999997), (1511040732000, 9.0, 'green', 8.7584509999999991), (1511040773000, 9.1, 'green', 8.4745030000000003), (1511040818000, 9.2, 'green', 8.933878), (1511040858000, 9.9, 'green', 7.9202039999999991), (1511040896000, 8.6, 'gold', 7.8945850000000002), (1511040931000, 10.3, 'green', 7.6601720000000002), (1511040996000, 6.7, 'red', 8.5650279999999999), (1511041031000, 10.0, 'green', 8.7161799999999996), (1511041067000, 7.5, 'red', 7.9621250000000003), (1511041096000, 9.0, 'green', 8.1414570000000008), (1511041114000, 9.2, 'green', 8.3518820000000016), (1511041155000, 8.7, 'gold', 9.4206369999999993), (1511041191000, 10.3, 'green', 8.8263420000000004), (1511041222000, 9.8, 'green', 8.4066119999999991), (1511041249000, 8.5, 'gold', 9.1490759999999991), (1511041291000, 9.4, 'green', 9.0670970000000004), (1511041312000, 10.0, 'green', 8.8903879999999997), (1511041347000, 9.8, 'green', 9.1862240000000011), (1511041380000, 9.3, 'green', 9.3911750000000005), (1511041405000, 8.3, 'gold', 9.1107110000000002), (1511041429000, 9.5, 'green', 9.4090059999999998), (1511041454000, 8.7, 'gold', 9.8702490000000012), (1511041498000, 7.1, 'red', 10.153846000000001), (1511041519000, 8.5, 'gold', 10.849730000000001)]
    }
}

BREATHING_HOURS_OFFSET = {
    'graphs/data/match/dylan/': 6,
    'graphs/data/practice/dylan/': 7,
    'graphs/data/match/william/': 5,
    'graphs/data/match/greg/': 7,
    'graphs/data/match/landon/': 7
}

def index(request):
    template = loader.get_template('../templates/home.html')
    context = {
        'title': 'Affect as Factor of Precision Performance',
        'author': 'William Caruso',
        'email': 'wcaruso@mit.edu'
    }
    return HttpResponse(template.render(context, request))


def graph(request):
    template = loader.get_template('../templates/graph.html')
    r_path = request.path
    participant_id = PATH_MAP[int(r_path[len(r_path)-2:])]
    path = 'graphs/data/' + participant_id

    p = participant_id.split('/')
    markers = SHOT_MARKERS[p[0]][p[1]]
    mod_markers = []
    graphs = None
    score = 0
    for i in range(len(markers)):
        time, sc, color, eda = markers[i]
        score += math.floor(sc)
        mod_markers.append((time, sc, color, eda, i+1))

    if len(Participants.objects.filter(shooter_id=participant_id)) > 0:
        graphs = Participants.objects.get(shooter_id=participant_id).graphs
        eda_chart = graphs.eda
        acc_chart = graphs.acc_raw
        bvp_chart = graphs.bvp
    else:
        # EDA
        # eda_stream_left = read_eda(path, 'left')
        eda_stream_right = read_eda(path, 'right')
        eda_chart = pandas_highcharts.core.serialize(eda_stream_right, render_to='eda-chart', output_type='json', title="Electrodermal Activity", zoom='x')

        # ACC
        # acc_stream_left = read_acc_seperate(path, 'left')
        acc_stream_right = read_acc_seperate(path, 'right')
        acc_chart = pandas_highcharts.core.serialize(acc_stream_right, render_to='acc-chart', output_type='json', title="Acceleration", zoom='x')

        # BVP
        # bvp_stream_left = read_bvp(path, 'left')
        bvp_stream_right = read_bvp(path, 'right')
        bvp_chart = pandas_highcharts.core.serialize(bvp_stream_right, render_to='bvp-chart', output_type='json', title="Blood Volume Pulse", zoom='x')

        g = Graphs(eda=eda_chart, bvp=bvp_chart, acc_raw=acc_chart)
        g.save()
        participant = Participants(name=p[1], shooter_id=participant_id, graphs=g)
        participant.save()

    breathing_stream, hr_stream = read_breathing_waveform(path)
    breathing_graph = pandas_highcharts.core.serialize(breathing_stream, render_to='breathing-chart', output_type='json', title="Breathing Rate", zoom='x')
    hr_graph = pandas_highcharts.core.serialize(hr_stream, render_to='hr-chart', output_type='json', title="Heart Rate", zoom='x')

    acc_stream = read_acc(path, 'left')
    acc_graph = pandas_highcharts.core.serialize(acc_stream, render_to='acc-ss-chart', output_type='json', title="Acceleration sqrt", zoom='x')

    graphs.hr = hr_graph
    graphs.breathing = breathing_graph
    graphs.acc = acc_graph
    graphs.save()

    context = {
        'player_id': int(r_path[len(r_path)-2:]),
        'name': participant_id,
        'score': score,
        'edaChart': eda_chart,
        'accChart': acc_chart,
        'accSsChart': acc_graph,
        'bvpChart': bvp_chart,
        'markers': mod_markers,
        'breathingChart': breathing_graph,
        'hrChart': hr_graph,
    }
    return HttpResponse(template.render(context, request))


# ---------------------------------------------------------------------------------------------------------------------

def read_eda(path, side):
    eda_filepath = path + side + '/EDA.csv'

    #read eda file
    eda_csv_stream = pd.read_csv(eda_filepath, header=None, names=[side + ' eda'])
    eda_csv_initial_timestamp = dt.utcfromtimestamp(eda_csv_stream.ix[0, side + ' eda'])
    eda_csv_initial_timestamp = eda_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    eda_csv_initial_timestamp = eda_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    eda_csv_stream = eda_csv_stream.drop(eda_csv_stream.index[:2])
    # add index
    index_eda_1 = pd.date_range(start=eda_csv_initial_timestamp, periods=len(eda_csv_stream.index), freq='250L')
    eda_csv_stream.set_index(index_eda_1, inplace=True)

    return eda_csv_stream


def read_acc_seperate(path, side):
    acc_filepath = path + side + '/ACC.csv'

    # read acc file
    print('Start Reading ACC file')
    x_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' x'], usecols=[0])
    acc_csv_initial_timestamp = dt.utcfromtimestamp(x_acc_csv_stream.ix[0, side + ' x'])
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    x_acc_csv_stream = x_acc_csv_stream.drop(x_acc_csv_stream.index[:2])
    x_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(x_acc_csv_stream.index), freq='31250U')
    x_acc_csv_stream.set_index(x_index_acc, inplace=True)

    y_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' y'], usecols=[1])
    y_acc_csv_stream = y_acc_csv_stream.drop(y_acc_csv_stream.index[:2])
    y_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(y_acc_csv_stream.index), freq='31250U')
    y_acc_csv_stream.set_index(y_index_acc, inplace=True)


    z_acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=[side + ' z'], usecols=[2])
    z_acc_csv_stream = z_acc_csv_stream.drop(z_acc_csv_stream.index[:2])
    z_index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(z_acc_csv_stream.index), freq='31250U')
    z_acc_csv_stream.set_index(z_index_acc, inplace=True)

    return [x_acc_csv_stream, y_acc_csv_stream, z_acc_csv_stream]


def read_acc(path, side):
    acc_filepath = path + side + '/ACC.csv'

    # read acc file
    print('Start Reading ACC file')
    acc_csv_stream = pd.read_csv(acc_filepath, header=None, names=['x', 'y', 'z'])
    acc_csv_initial_timestamp = dt.utcfromtimestamp(acc_csv_stream.ix[0, 'x'])
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    acc_csv_initial_timestamp = acc_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    acc_csv_stream = acc_csv_stream.drop(acc_csv_stream.index[:2])
    index_acc = pd.date_range(start=acc_csv_initial_timestamp, periods=len(acc_csv_stream.index), freq='31250U')

    # calculate rolling avg. like Empatica Connect
    # diffs_x = pd.rolling_apply(acc_csv_stream['x'], 2, lambda x: abs(x[0] - x[1]))
    # diffs_y = pd.rolling_apply(acc_csv_stream['y'], 2, lambda x: abs(x[0] - x[1]))
    # diffs_z = pd.rolling_apply(acc_csv_stream['z'], 2, lambda x: abs(x[0] - x[1]))
    #
    # # diffs_x = diffs_x.drop(diffs_x.index[:1])
    # # diffs_y = diffs_y.drop(diffs_y.index[:1])
    # # diffs_z = diffs_z.drop(diffs_z.index[:1])
    #
    # combined = pd.concat([diffs_x, diffs_y, diffs_z], axis=1)
    # print combined
    # maxed = combined.apply(max, axis=1)
    # print 'maxed: ', maxed
    # averaged = pd.rolling_sum(maxed, 1)

    acc_csv_stream **= 2
    acc_csv_stream = acc_csv_stream.apply(sum, axis=1)
    acc_csv_stream **= 0.5
    acc_csv_stream = acc_csv_stream.to_frame()
    acc_csv_stream.set_index(index_acc, inplace=True)
    print acc_csv_stream
    return acc_csv_stream


def read_bvp(path, side):
    bvp_filepath = path + side + '/BVP.csv'

    # read bvp file
    print('Start Reading BVP file')
    bvp_csv_stream = pd.read_csv(bvp_filepath, header=None, names=[side + ' bvp'])
    bvp_csv_initial_timestamp = dt.utcfromtimestamp(bvp_csv_stream.ix[0, side + ' bvp'])
    bvp_csv_initial_timestamp = bvp_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    bvp_csv_initial_timestamp = bvp_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))
    bvp_csv_stream = bvp_csv_stream.drop(bvp_csv_stream.index[:2])
    index_bvp = pd.date_range(start=bvp_csv_initial_timestamp, periods=len(bvp_csv_stream.index), freq='15625U')
    bvp_csv_stream.set_index(index_bvp, inplace=True)

    return bvp_csv_stream


def read_breathing_waveform(path):
    breathing_path = path + 'bio/summary.csv'
    breathing_csv_stream = pd.read_csv(breathing_path, header=None, usecols=[0,2])
    hr_csv_stream = pd.read_csv(breathing_path, header=None, usecols=[1])
    s = breathing_csv_stream.ix[1][0]
    s = s.split('.')
    t = time.mktime(dt.strptime(s[0], "%d/%m/%Y %H:%M:%S").timetuple())
    breathing_csv_initial_timestamp = dt.utcfromtimestamp(t) + datetime.timedelta(hours=BREATHING_HOURS_OFFSET[path], milliseconds=int(s[1]))
    breathing_csv_initial_timestamp = breathing_csv_initial_timestamp.replace(tzinfo=tz.gettz('UTC'))
    breathing_csv_initial_timestamp = breathing_csv_initial_timestamp.astimezone(tz.gettz('America/New_York'))

    breathing_csv_stream = breathing_csv_stream.drop(breathing_csv_stream.index[:1])
    index_breathing = pd.date_range(start=breathing_csv_initial_timestamp, periods=len(breathing_csv_stream.index), freq='1000000U')
    breathing_csv_stream[2] = pd.to_numeric(breathing_csv_stream[2])
    breathing_csv_stream.set_index(index_breathing, inplace=True)

    hr_csv_stream = hr_csv_stream.drop(hr_csv_stream.index[:1])
    hr_csv_stream[1] = pd.to_numeric(hr_csv_stream[1])
    hr_csv_stream.set_index(index_breathing, inplace=True)

    return breathing_csv_stream, hr_csv_stream

