コード例 #1
0
ファイル: reports.py プロジェクト: iamvazu/flow-dashboard
 def entityData(self, event):
     row = [
         tools.iso_date(event.date_start),
         tools.iso_date(event.date_end), event.title, event.details,
         event.color
     ]
     return row
コード例 #2
0
    def test_habit_calls(self):
        # List
        response = self.get_json("/api/habit", {}, headers=self.api_headers)
        h = response.get('habits')[0]
        self.assertEqual(h.get('name'), "Run")

        # Update
        response = self.post_json("/api/habit", {
            'id': h.get('id'),
            'name': 'Walk'
        },
                                  headers=self.api_headers)
        h = response.get('habit')
        self.assertEqual(h.get('name'), 'Walk')

        # Actions
        today = datetime.now()
        DAY = tools.iso_date(today - timedelta(days=1))
        hid = h.get('id')
        actions = [{
            'action': 'commit',
            'expected_prop': 'committed'
        }, {
            'action': 'toggle',
            'expected_prop': 'done'
        }]
        for act in actions:
            params = {'habit_id': hid, 'date': DAY}
            response = self.post_json("/api/habit/%s" % act.get('action'),
                                      params,
                                      headers=self.api_headers)
            hd = response.get('habitday')
            prop = act.get('expected_prop')
            self.assertTrue(hd.get(prop))

        # Recent
        response = self.get_json("/api/habit/recent", {'days': 3},
                                 headers=self.api_headers)
        habitdays = response.get('habitdays')
        self.assertTrue(hd.get('id') in habitdays)

        # Recent
        params = {
            'start_date': tools.iso_date(today - timedelta(days=2)),
            'end_date': tools.iso_date(today)
        }
        response = self.get_json("/api/habit/range",
                                 params,
                                 headers=self.api_headers)
        habitdays = response.get('habitdays')
        self.assertTrue(hd.get('id') in habitdays)

        # Delete
        response = self.post_json("/api/habit/delete", {'id': h.get('id')},
                                  headers=self.api_headers)
        h = Habit.get_by_id(h.get('id'), parent=self.u.key)
        self.assertIsNone(h)  # Confirm deletion
コード例 #3
0
ファイル: reports.py プロジェクト: maximsch2/flow-dashboard
 def add_date_filters(self, start=None, end=None):
     if start:
         self.FILTERS.append(
             "%s >= DATETIME('%s 00:00:00')" %
             (self.start_att, tools.iso_date(tools.dt_from_ts(start))))
     if end:
         self.FILTERS.append(
             "%s < DATETIME('%s 23:59:59')" %
             (self.start_att, tools.iso_date(tools.dt_from_ts(end))))
コード例 #4
0
ファイル: reports.py プロジェクト: akatsoulas/flow-dashboard
 def entityData(self, event):
     row = [
         tools.iso_date(event.date_start),
         tools.iso_date(event.date_end),
         event.title,
         event.details,
         event.color
     ]
     return row
コード例 #5
0
ファイル: reports.py プロジェクト: zhengge2017/flow-dashboard
 def entityData(self, td):
     data = tools.getJson(td.data)
     data_text = []
     for key, val in data.items():
         data_text.append("%s:%s" % (key, val))
     row = [tools.iso_date(td.date), ', '.join(data_text)]
     return row
コード例 #6
0
    def test_habit_calls(self):
        # List
        response = self.get_json("/api/habit", {}, headers=self.api_headers)
        h = response.get('habits')[0]
        self.assertEqual(h.get('name'), "Run")

        # Update
        response = self.post_json("/api/habit", {'id': h.get('id'), 'name': 'Walk'}, headers=self.api_headers)
        h = response.get('habit')
        self.assertEqual(h.get('name'), 'Walk')

        # Actions
        today = datetime.now()
        DAY = tools.iso_date(today - timedelta(days=1))
        hid = h.get('id')
        actions = [
            {'action': 'commit', 'expected_prop': 'committed'},
            {'action': 'toggle', 'expected_prop': 'done'}
        ]
        for act in actions:
            params = {
                'habit_id': hid,
                'date': DAY
            }
            response = self.post_json("/api/habit/%s" % act.get('action'), params, headers=self.api_headers)
            hd = response.get('habitday')
            prop = act.get('expected_prop')
            self.assertTrue(hd.get(prop))

        # Recent
        response = self.get_json("/api/habit/recent", {'days': 3}, headers=self.api_headers)
        habitdays = response.get('habitdays')
        self.assertTrue(hd.get('id') in habitdays)

        # Recent
        params = {
            'start_date': tools.iso_date(today - timedelta(days=2)),
            'end_date': tools.iso_date(today)
        }
        response = self.get_json("/api/habit/range", params, headers=self.api_headers)
        habitdays = response.get('habitdays')
        self.assertTrue(hd.get('id') in habitdays)

        # Delete
        response = self.post_json("/api/habit/delete", {'id': h.get('id')}, headers=self.api_headers)
        h = Habit.get_by_id(h.get('id'), parent=self.u.key)
        self.assertIsNone(h)  # Confirm deletion
コード例 #7
0
ファイル: reports.py プロジェクト: akatsoulas/flow-dashboard
 def entityData(self, jrnl):
     row = [
         tools.iso_date(jrnl.date),
         ', '.join([key.id() for key in jrnl.tags]),
         str(jrnl.location) if jrnl.location else "",
         jrnl.data if jrnl.data else ""
     ]
     return row
コード例 #8
0
ファイル: reports.py プロジェクト: maximsch2/flow-dashboard
 def entityData(self, jrnl):
     row = [
         tools.iso_date(jrnl.date),
         ', '.join([key.id() for key in jrnl.tags]),
         str(jrnl.location) if jrnl.location else "",
         jrnl.data if jrnl.data else ""
     ]
     return row
コード例 #9
0
ファイル: reports.py プロジェクト: maximsch2/flow-dashboard
 def entityData(self, hd):
     habit = hd.habit.get()
     row = [
         tools.sdatetime(hd.dt_created, fmt=DATE_FMT),
         tools.sdatetime(hd.dt_updated, fmt=DATE_FMT),
         tools.iso_date(hd.date), habit.name if habit else "",
         "1" if hd.done else "0", "1" if hd.committed else "0"
     ]
     return row
コード例 #10
0
ファイル: reports.py プロジェクト: akatsoulas/flow-dashboard
 def entityData(self, td):
     data = tools.getJson(td.data)
     data_text = []
     for key, val in data.items():
         data_text.append("%s:%s" % (key, val))
     row = [
         tools.iso_date(td.date),
         ', '.join(data_text)
     ]
     return row
コード例 #11
0
ファイル: reports.py プロジェクト: akatsoulas/flow-dashboard
 def entityData(self, hd):
     habit = hd.habit.get()
     row = [
         tools.sdatetime(hd.dt_created, fmt=DATE_FMT),
         tools.sdatetime(hd.dt_updated, fmt=DATE_FMT),
         tools.iso_date(hd.date),
         habit.name if habit else "",
         "1" if hd.done else "0",
         "1" if hd.committed else "0"
     ]
     return row
コード例 #12
0
 def get_contributions_on_day(self, date):
     '''
     Currently scraping Github public overview page (no API yet)
     '''
     iso_date = tools.iso_date(date)
     response = urlfetch.fetch("https://github.com/%s?tab=overview" % self.github_username, deadline=30)
     if response.status_code == 200:
         bs = BeautifulSoup(response.content, "html.parser")
         commits_on_day = bs.find('rect', {'data-date': iso_date}).get('data-count', 0)
         return commits_on_day
     else:
         logging.error("Error getting contributions")
コード例 #13
0
ファイル: api.py プロジェクト: maximsch2/flow-dashboard
 def list(self, d):
     days = self.request.get_range('days', default=4)
     today = datetime.today()
     cursor = today
     journal_keys = []
     for i in range(days):
         iso_date = tools.iso_date(cursor)
         journal_keys.append(
             ndb.Key('MiniJournal', iso_date, parent=self.user.key))
         cursor -= timedelta(days=1)
     journals = ndb.get_multi(journal_keys)
     self.set_response({'journals': [j.json() for j in journals if j]},
                       success=True)
コード例 #14
0
    def test_habit_report(self):
        habit_run = Habit.Create(self.u)
        habit_run.Update(name="Run")
        habit_run.put()
        marked_done, hd = HabitDay.Toggle(habit_run, datetime.today())

        self._test_report(
            {'type': REPORT.HABIT_REPORT},
            [["Created", "Updated", "Date", "Habit", "Done", "Committed"],
             [
                 tools.sdatetime(hd.dt_created, fmt="%Y-%m-%d %H:%M:%S %Z"),
                 tools.sdatetime(hd.dt_updated, fmt="%Y-%m-%d %H:%M:%S %Z"),
                 tools.iso_date(datetime.now()), "Run", "1", "0"
             ]])
コード例 #15
0
ファイル: github.py プロジェクト: akatsoulas/flow-dashboard
 def get_contributions_on_date_range(self, date_range):
     '''
     Currently scraping Github public overview page (no API yet)
     '''
     response = urlfetch.fetch("https://github.com/%s?tab=overview" % self.github_username, deadline=30)
     if response.status_code == 200:
         bs = BeautifulSoup(response.content, "html.parser")
         commits_dict = {}
         for date in date_range:
             iso_date = tools.iso_date(date)
             commits_on_day = bs.find('rect', {'data-date': iso_date}).get('data-count', 0)
             commits_dict[date] = commits_on_day
         return commits_dict
     else:
         logging.error("Error getting contributions")
コード例 #16
0
    def test_habit_report(self):
        habit_run = Habit.Create(self.u)
        habit_run.Update(name="Run")
        habit_run.put()
        marked_done, hd = HabitDay.Toggle(habit_run, datetime.today())

        self._test_report(
            {'type': REPORT.HABIT_REPORT},
            [
                ["Created", "Updated", "Date", "Habit", "Done", "Committed"],
                [
                    tools.sdatetime(hd.dt_created, fmt="%Y-%m-%d %H:%M:%S %Z"),
                    tools.sdatetime(hd.dt_updated, fmt="%Y-%m-%d %H:%M:%S %Z"),
                    tools.iso_date(datetime.now()),
                    "Run",
                    "1",
                    "0"
                ]
            ]
        )
コード例 #17
0
ファイル: reports.py プロジェクト: akatsoulas/flow-dashboard
 def add_date_filters(self, start=None, end=None):
     if start:
         self.FILTERS.append("%s >= DATETIME('%s 00:00:00')" % (self.start_att, tools.iso_date(tools.dt_from_ts(start))))
     if end:
         self.FILTERS.append("%s < DATETIME('%s 23:59:59')" % (self.start_att, tools.iso_date(tools.dt_from_ts(end))))
コード例 #18
0
 def fetch_daily_panel_data(self, since=None, until=None):
     self._maybe_get_habits()
     self._maybe_get_journal_questions()
     if not since:
         since = datetime.combine((datetime.now() - timedelta(days=self.days_ago)).date(), time(0, 0))
     if not until:
         until = datetime.combine((datetime.now() - timedelta(days=self.days_ago_end)).date(), time(0, 0))
     rows = []
     habitdays_by_day = tools.partition(
         HabitDay.Range(self.user, self.habits.values(), since, until_date=until),
         lambda hd: tools.iso_date(hd.date)
     )
     tasks_by_day = tools.partition(
         Task.DueInRange(self.user, since, until, limit=500),
         lambda t: tools.iso_date(t.dt_due)
     )
     readables_by_day = tools.partition(
         Readable.Fetch(self.user, read=True,
                        since=tools.iso_date(since),
                        until=tools.iso_date(until)),
         lambda r: tools.iso_date(r.dt_read)
     )
     journals, iso_dates = MiniJournal.Fetch(self.user, start=since, end=until)
     journals_by_day = tools.partition(journals, lambda jrnl: tools.iso_date(jrnl.date))
     cursor = since
     while cursor <= until:
         iso_date = tools.iso_date(cursor)
         tasks = tasks_by_day.get(iso_date, [])
         habitdays = habitdays_by_day.get(iso_date, [])
         readables = readables_by_day.get(iso_date, [])
         journals = journals_by_day.get(iso_date, [])
         journal = journals[0] if journals else None
         tasks_done = tasks_undone = habits_done = habits_cmt = habits_cmt_undone = items_read = 0
         row = {}
         for t in tasks:
             if t.is_done():
                 tasks_done += 1
             else:
                 tasks_undone += 1
         habits_checklist = self.habits.keys()  # list of habit IDs
         for hd in habitdays:
             hid = hd.habit.id()
             h = self.habits.get(hid)
             if h:
                 habits_checklist.remove(hid)
                 row[self._habit_col(h)] = 'true' if hd.done else 'false'
             if hd.done:
                 habits_done += 1
             if hd.committed:
                 habits_cmt += 1
                 if not hd.done:
                     habits_cmt_undone += 1
         if habits_checklist:
             # Missing habit-days, need to create columns anyway
             for hid in habits_checklist:
                 h = self.habits.get(hid)
                 if h:
                     row[self._habit_col(h)] = 'false'
         items_read = len(readables)
         fav_items_read = len([r for r in readables if r.favorite])
         row.update({
             "id": iso_date,
             "date": iso_date,
             "tasks_done": tasks_done,
             "tasks_undone": tasks_undone,
             "habits_done": habits_done,
             "habits_cmt": habits_cmt,
             "habits_cmt_undone": habits_cmt_undone,
             "items_read": items_read,
             "fav_items_read": fav_items_read
         })
         for q in self.journal_questions:
             name = q.get('name')
             value = None
             if journal:
                 value = journal.get_data_value(name)
                 numeric = q.get('response_type') in JOURNAL.NUMERIC_RESPONSES
                 if numeric:
                     value = tools.safe_number(value, default=0)
                 elif isinstance(value, basestring):
                     value = tools.removeNonAscii(value)
                 else:
                     value = str(value) if value else ""
             row[self._journal_col(q)] = value
         rows.append(row)
         cursor += timedelta(days=1)
     return rows
コード例 #19
0
 def fetch_daily_panel_data(self, since=None, until=None):
     self._maybe_get_habits()
     self._maybe_get_journal_questions()
     if not since:
         since = datetime.combine(
             (datetime.now() - timedelta(days=self.days_ago)).date(),
             time(0, 0))
     if not until:
         until = datetime.combine(
             (datetime.now() - timedelta(days=self.days_ago_end)).date(),
             time(0, 0))
     rows = []
     habitdays_by_day = tools.partition(
         HabitDay.Range(self.user,
                        self.habits.values(),
                        since,
                        until_date=until),
         lambda hd: tools.iso_date(hd.date))
     tasks_by_day = tools.partition(
         Task.DueInRange(self.user, since, until, limit=500),
         lambda t: tools.iso_date(t.dt_due))
     readables_by_day = tools.partition(
         Readable.Fetch(self.user,
                        read=True,
                        since=tools.iso_date(since),
                        until=tools.iso_date(until)),
         lambda r: tools.iso_date(r.dt_read))
     journals, iso_dates = MiniJournal.Fetch(self.user,
                                             start=since,
                                             end=until)
     journals_by_day = tools.partition(
         journals, lambda jrnl: tools.iso_date(jrnl.date))
     cursor = since
     while cursor <= until:
         iso_date = tools.iso_date(cursor)
         tasks = tasks_by_day.get(iso_date, [])
         habitdays = habitdays_by_day.get(iso_date, [])
         readables = readables_by_day.get(iso_date, [])
         journals = journals_by_day.get(iso_date, [])
         journal = journals[0] if journals else None
         tasks_done = tasks_undone = habits_done = habits_cmt = habits_cmt_undone = items_read = 0
         row = {}
         for t in tasks:
             if t.is_done():
                 tasks_done += 1
             else:
                 tasks_undone += 1
         habits_checklist = self.habits.keys()  # list of habit IDs
         for hd in habitdays:
             hid = hd.habit.id()
             h = self.habits.get(hid)
             if h:
                 habits_checklist.remove(hid)
                 row[self._habit_col(h)] = 'true' if hd.done else 'false'
             if hd.done:
                 habits_done += 1
             if hd.committed:
                 habits_cmt += 1
                 if not hd.done:
                     habits_cmt_undone += 1
         if habits_checklist:
             # Missing habit-days, need to create columns anyway
             for hid in habits_checklist:
                 h = self.habits.get(hid)
                 if h:
                     row[self._habit_col(h)] = 'false'
         items_read = len(readables)
         fav_items_read = len([r for r in readables if r.favorite])
         row.update({
             "id": iso_date,
             "date": iso_date,
             "tasks_done": tasks_done,
             "tasks_undone": tasks_undone,
             "habits_done": habits_done,
             "habits_cmt": habits_cmt,
             "habits_cmt_undone": habits_cmt_undone,
             "items_read": items_read,
             "fav_items_read": fav_items_read
         })
         for q in self.journal_questions:
             name = q.get('name')
             value = None
             if journal:
                 value = journal.get_data_value(name)
                 numeric = q.get(
                     'response_type') in JOURNAL.NUMERIC_RESPONSES
                 if numeric:
                     value = tools.safe_number(value, default=0)
                 elif isinstance(value, basestring):
                     value = tools.removeNonAscii(value)
                 else:
                     value = str(value) if value else ""
             row[self._journal_col(q)] = value
         rows.append(row)
         cursor += timedelta(days=1)
     return rows