-
Notifications
You must be signed in to change notification settings - Fork 2
/
whenwillibeadad.py
50 lines (36 loc) · 1.39 KB
/
whenwillibeadad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 11 09:05:56 2016
@author: aclerc
"""
import pandas as pd
import datetime as dt
#When will I be a dad?
def todays_prob(due_date = dt.datetime(2016,7,21,12)):
df = pd.read_csv("probs.csv")
today = dt.datetime.now()
days_to_due = int((today - due_date).total_seconds()/3600.0/24.0)
#raw probability
raw_prob = df["Prob"][df["Day relative to due date"] == days_to_due]
#conditional probability
past_prob = sum(df["Prob"][df["Day relative to due date"] < days_to_due])
cond_prob = raw_prob / (1.0 - past_prob)
cond_prob = float(cond_prob) * 100.
return cond_prob
def cumulative_graph(due_date = dt.datetime(2016,7,21,12)):
from flask import render_template
import os
df = pd.read_csv("probs.csv")
today = dt.datetime.now()
days_to_due = int((today - due_date).total_seconds()/3600.0/24.0)
df['Date'] = df['Day relative to due date'].apply( lambda d : dt.timedelta(days=d)) + due_date
df['Date'] = pd.to_datetime(df['Date']).dt.strftime('"%Y-%m-%d, ')
df["Cumulative"] = df["Prob"].cumsum()
df['newline'] = u'\n" + '
fn = os.path.dirname(__file__)+'/static/graph.html'
with open(fn) as f:
s = f.read()
s = s.replace("{data}",df[['Date','Cumulative','newline']].to_string(header=False,index=False))
return s
if __name__ == "__main__":
y = cumulative_graph()