thescholarsavenue / gc1213

Relive this years' GC
http://thescholarsavenue.github.io/gc1213
0 stars 1 forks source link

d3 timeline #3

Open pnpranavrao opened 11 years ago

pnpranavrao commented 11 years ago

The d3-timeline plug in (https://github.com/jiahuang/d3-timeline/tree/master/src) requires data to have this attribute : " times: [{"starting_time": 1355752800000, "ending_time": 1355759900000}, {"starting_time": 1355767900000, "ending_time": 1355774400000}"

The rest of the json file you have can remain exactly the same, only the "times" property above needs to be added for each "event" entry.

Also note that there's a hover function provided by the timeline - so most of the code you have below the load_data func in main.js just goes there.

Here's a tiny function I wrote to convert the current event dates to UTC format. Just run it on the json file properly. (Don't have unix now on my PC)

import datetime
def process_date(given_date):
epoch = datetime.datetime(1970, 1, 1)
month = 0
day = 0
year = 2013
month_dict = {"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12}
date_items = given_date.split(" ")
g_month = str(date_items[0])
month = month_dict[g_month]
day = int(date_items[1].split(",")[0])
g_year = str(date_items[2])
if "12" in g_year:
    year = 2012
start = datetime.datetime(year=year,month=month,day=day)
end = datetime.datetime(year=year,month=month,day=day+1)
return {"starting_time":(start-epoch).total_seconds(),"ending_time":(end-epoch).total_seconds()}

Example : s = "Apr 7, '13" process_date(s) {'ending_time': 1365379200.0, 'starting_time': 1365292800.0}

pnpranavrao commented 11 years ago

Slight correction to the function

def process_date(given_date): epoch = datetime.datetime(1970, 1, 1) month = 0 day = 0 year = 2013 month_dict = {"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12} date_items = given_date.split(" ") g_month = str(date_items[0]) month = month_dict[g_month] day = int(date_items[1].split(",")[0]) g_year = str(date_items[2]) if "12" in g_year: year = 2012 start = datetime.datetime(year=year,month=month,day=day) end = start + datetime.timedelta(days=1) return {"starting_time":(start-epoch).total_seconds(),"ending_time":(end-epoch).total_seconds()}