Created
February 9, 2018 09:21
-
-
Save zeffii/d6b19262a0adb3230da2590d8a9d476c to your computer and use it in GitHub Desktop.
repeating insuline values with time gaps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, date, timedelta | |
csv = """\ | |
01/01/2018,38 | |
12/01/2018,38 | |
15/01/2018,34 | |
22/01/2018,34 | |
25/01/2018,38 | |
31/01/2018,40 | |
02/02/2018,36 | |
""" | |
date_format = "%d/%m/%Y" | |
csv_data = [] | |
for item in csv.splitlines(): | |
k, v = item.split(',') | |
csv_data.append((k, int(v))) | |
csv_data_dict = {date: insuline for date, insuline in csv_data} | |
def generate_interpolation_data(csv_data): | |
start = csv_data[0][0] | |
end = csv_data[-1][0] | |
a = datetime.strptime(start, date_format) | |
b = datetime.strptime(end, date_format) | |
delta = b - a | |
num_days = delta.days | |
data = [] | |
insuline = 0 | |
for i in range(delta.days + 1): | |
day = a + timedelta(days=i) | |
day_str = day.strftime(date_format) | |
insuline = csv_data_dict.get(day_str, insuline) | |
data.append([day_str, insuline]) | |
return data | |
def gid(): | |
return generate_interpolation_data(csv_data) | |
print(gid()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment