Skip to content

Instantly share code, notes, and snippets.

@0xDBFB7
Created April 12, 2019 23:03
Show Gist options
  • Save 0xDBFB7/30a1f8c7da159ce2de1f40472448f1f1 to your computer and use it in GitHub Desktop.
Save 0xDBFB7/30a1f8c7da159ce2de1f40472448f1f1 to your computer and use it in GitHub Desktop.
2019-01-10
attended
2019-01-17
attended
2019-01-31
attended
2019-02-07
attended
2019-02-28
attended
2019-03-07
attended
2019-03-21
attended
2019-03-28
attended
8 out of a worst-case 15, 53%
#!/usr/bin/env python
import json
import numpy as np
import datetime
import math
# Helper functions
def date_ymd_to_timestamp_ms(y,m,d):
return datetime.datetime(y,m,d).timestamp()*1e3
# LOAD DATA
json_file = "location_history.json"
# Read the file
main_dict = json.load(open(json_file)) # This can take a bit of time
# data is a big list of dicts.
data = main_dict['locations']
n = len(data) # Number of timesteps
timestampMs = np.zeros(n) # in milliseconds
positions = np.zeros([n,2]) # in degrees
accuracy = np.zeros(n) # in %
activity = {}
for i in range(n):
point = data[i]
timestampMs[i] = float(point['timestampMs'])
positions[i] = np.array([float(point['latitudeE7']),float(point['longitudeE7'])-180.0e7])/1e7
accuracy[i] = point['accuracy']
if 'activity' in point: activity[i] = point['activity']
n_act = len(activity.keys())
print("Total of points: %d"%n)
print("Total of points with activity: %d (%0.1f%%)"%(n_act,int(n_act/n*100)))
ds = []
for i in range(0,len(positions)):
if((positions[i][0]-43.7734535) < 0.0001): #ignore longitude - google changed formats recently
d = datetime.datetime.utcfromtimestamp(int(timestampMs[i]/1e3))
if(d.isoweekday() == 4 and d.hour in range(10, 14)):
ds.append(d)
print(d.strftime('%Y-%m-%d %H:%M:%S'))
d1 = datetime.date(2019, 1, 1) # start date
d2 = datetime.date(2019, 4, 12) # end date
delta = d2 - d1 # timedelta
counter = 0
possible_counter = 0
for i in range(delta.days + 1):
a = 0
# print(d1 + datetime.timedelta(i))
for t in ds:
if((d1 + datetime.timedelta(i)) == t.date() and a == 0):
print(t.strftime('%Y-%m-%d'))
print("attended")
a=1
counter+=1
if((d1 + datetime.timedelta(i)).isoweekday() == 4):
possible_counter+=1
print("{} out of a worst-case {}, {}%".format(counter,possible_counter,int(counter/possible_counter*100.0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment