示例#1
0
    def testDisplayingOfHTMLRenderedMarkdown(self):

        self.maxDiff = None

        self.diary_app.diary = d.Diary(tempDiaryFileName)

        with open(noteFileName) as f:
            note = f.read()

        with open(HTMLNoteFileName) as f:
            refNoteHtml = f.read().rstrip()

        self.diary_app.displayHTMLRenderedMarkdown(note)

        self.diary_app.web.loadFinished.connect(self._loadFinished)
        self.noteHtml = None
        app.exec_()

        # CSS path is machine-dependent so we change it
        newNoteHtml = ""
        for line in self.noteHtml.splitlines():
            if 'github-markdown.css' in line:
                line = '<link rel="stylesheet" href="css/github-markdown.css">'
            if 'github-pygments.css' in line:
                line = '<link rel="stylesheet" href="css/github-pygments.css">'
            newNoteHtml += line
            newNoteHtml += '\n'
        # Remove the added extra newline
        self.noteHtml = newNoteHtml[:-1]

        self.assertMultiLineEqual(self.noteHtml, refNoteHtml)
示例#2
0
    def get_diary(self, u):
        """
        This function takes the simulation data in terms of a list of \
        :class:`universe.Universe` and creates a list \
        of :class:`diary.Diary` that contain the activity diaries. \
        One per each household in the simulation.

        :param universe.Universe u: contains all of the simulation data
        :return: the activity diaries (1 entry per person)
        :rtype: list of :class:`diary.Diary`
        """

        # the list of diaries for each agent in the household
        diary_hhld = list()

        # the household diaries for each agent in the simulation
        for p in u.people:

            # get the information about the diary
            t, act, loc = self.get_diary_help(u.clock.hist_time,
                                              p.hist_activity, p.hist_local)

            # add the diary to the list
            diary_hhld.append(diary.Diary(t, act, loc))

        return diary_hhld
示例#3
0
    def get_diary(self):
        """
        This function output the result of the simulation in terms of an activity diary.

        :return: the activity diary describing the behavior of the agent
        :rtype: diary.Diary
        """

        # the indices of simulation data
        idx = self.clock.hist_time != -1
        idx = idx.flatten()

        # the time
        t = self.clock.hist_time[idx].flatten()

        # the array of the activities
        hist_act = self.hist_activity[idx]

        # the array of the locations
        hist_loc = self.hist_local[idx]

        # make the time continuous
        t_all = mg.fill_out_time(t)

        # fill out the time in between events to get data that corresponds to contiguous time
        act_all = mg.fill_out_data(t, hist_act)

        # fill out the location data in between events that corresponds to contiguous time
        loc_all = mg.fill_out_data(t, hist_loc)

        # create the activity diary
        d = diary.Diary(t=t_all, act=act_all, local=loc_all)

        return d
def addDiary(handler, datestr, devid, data):
    """ データの追加
    """
    # 日時の変換に失敗したら、現在日時を代入する
    date = utility.str2dt(datestr)
    if date is None:
        # 世界標準時 + 9時間 = 日本標準時
        date = dt.now() + timedelta(hours=9)
    try:
        diary.Diary(date).add(date, devid, data)
    except RuntimeError as error:
        logging.warning(error.message)
    def loadDiary(self, fname):
        """Load diary from file.

        Display last note from the diary if it exists.

        Args:
            fname (str): Path to a file containing a diary.
        """
        if self.text.document().isModified():
            reply = self.promptToSaveOrDiscard()

            if reply == QtWidgets.QMessageBox.Cancel:
                return

            elif reply == QtWidgets.QMessageBox.Discard:
                self.text.document().setModified(False)

            elif reply == QtWidgets.QMessageBox.Save:
                self.saveNote()

        self.updateRecentDiaries(fname)
        self.diary = diary.Diary(fname)

        # Save the diary path to QWebEnginePage, so we can fix external links,
        # which (for some reason) look like file://DIARY_PATH/EXTERNAL_LINK
        self.page.diaryPath = fname

        self.loadTree(self.diary.data)

        # Display empty editor if the diary has no notes (e.g., new diary)
        if not self.diary.data:
            self.text.clear()
            self.stack.setCurrentIndex(0)
            return

        # Check if we saved a recent noteId for this diary and open it if we
        # did, otherwise open the newest note
        lastNoteId = ""
        for recentNote in self.recentNotes:
            if recentNote in (metaDict["note_id"]
                              for metaDict in self.diary.data):
                lastNoteId = recentNote
                break

        if lastNoteId == "":
            lastNoteId = self.diary.data[-1]["note_id"]

        self.tree.setCurrentItem(
            self.tree.findItems(lastNoteId, QtCore.Qt.MatchExactly)[0])
        self.stack.setCurrentIndex(1)
示例#6
0
    def edit(self):
        """グラフを描画するJSONの1日分のボディを生成する
        Arguments:
            date {[datatime]} -- 日付
        Returns:
            dicstionary list -- 1日分のボディ部分の辞書リスト
        """

        # 空のボディを作成
        rows = []
        rows_append = rows.append  # 参照を事前に読み込むことで高速化

        # 必要な日誌を読み込みリストに登録
        open_diarys = [diary.Diary(self.date).get(self.date, devid) for devid in sensor.get_list_devid(self.tag)]

        # 引数の日付の00:00~23:59まで1分間隔
        start = dt.combine(self.date, datetime.time.min)
        for time in (start + datetime.timedelta(minutes=x) for x in range(1440)):
            # 横軸の入力
            new_line = [{
                'v': utility.gen_jsdatatime(time)
            }]

            # 縦軸の入力
            new_line_append = new_line.append  # 参照を事前に読み込むことで高速化
            timestr = utility.t2str(time)
            for open_diary in open_diarys:
                try:
                    new_line_append({
                        'v': open_diary[timestr][self.kind]
                    })
                except KeyError:
                    new_line_append({
                        'v': None
                    })

            # ボディの末端に追加
            rows_append({
                'c': new_line
            })

        # 生成したボディを返す
        return rows
示例#7
0
    def onAddNewClicked(self, event):
        """Is triggered when add new diary
        button is clicked."""

        date = self.dateCtrl.GetValue()
        new_diary = diary.Diary(int(date.Format("%Y")), int(date.Format("%m")),
                                int(date.Format("%d")))
        new_diary.set_hour(int(self.hourCombo.GetValue()))
        new_diary.set_minute(int(self.minCombo.GetValue()))
        new_diary.set_title(self.titleCombo.GetValue())
        new_diary.set_activity(self.actCombo.GetValue())
        new_diary.set_description(self.descText.GetValue())

        db.db_connection.save_to_db(new_diary)

        self.appendTitleCombo(self.titleCombo.GetValue())
        self.appendActivityCombo(self.actCombo.GetValue())
        self.updateCombos()
        self.updateListItems()
示例#8
0
def search_db(search_str):
    """Searches the diary table.
    All diaries where  title, activity or description 
    contains search string is returned in a list of Diary."""

    conn = sqlite3.connect('db' + os.sep + 'wdiary.db')
    cur = conn.cursor()

    search_str = '%' + search_str + '%'
    l_diary = []
    for row in cur.execute(
            """SELECT * FROM diary 
                              WHERE title LIKE ?
                              OR activity LIKE ?
                              OR description LIKE ?""",
        (search_str, search_str, search_str)):
        l_diary.append(
            diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6], row[7],
                        row[8], row[0]))

    conn.close()
    return l_diary
示例#9
0
    def activity_diary(self):
        """
        This function returns the activity diary for each person

        Each person will attain the following tuple

        #. grouping of the index for each activity
        #. the day, (start-time, end-time), activity code, and location for each activity-event, in a numeric format
        #. the same as above in a string format

        :return:
        """

        # the time of each step in the simulation [universal time, minutes]
        t = self.u.hist_time

        # the (index, numerical diary, string diary) for each
        x = [
            diary.Diary(t, p.hist_activity, p.hist_local)
            for p in self.u.people
        ]

        return x
示例#10
0
def search_db_date(startdate, enddate):
    """Searches the diary table.
    All diaries between and including start-
    and enddate is returned as a list of Diary."""

    syear = startdate.year
    smonth = startdate.month
    sday = startdate.day

    eyear = enddate.year
    emonth = enddate.month
    eday = enddate.day

    conn = sqlite3.connect('db' + os.sep + 'wdiary.db')
    cur = conn.cursor()

    l_diary = []

    if syear == eyear and smonth == emonth:
        for row in cur.execute(
                """SELECT * FROM diary WHERE
                                  year == ?
                                  AND month == ?
                                  AND day >= ?
                                  AND day <= ?""",
            (syear, smonth, sday, eday)):
            l_diary.append(
                diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6],
                            row[7], row[8], row[0]))

    if syear == eyear and smonth < emonth:
        for row in cur.execute(
                """SELECT * FROM diary WHERE
                                  year == ?
                                  AND month == ?
                                  AND day >= ?""", (syear, smonth, sday)):
            l_diary.append(
                diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6],
                            row[7], row[8], row[0]))

        for row in cur.execute(
                """SELECT * FROM diary WHERE
                                  year == ?
                                  AND month > ?
                                  AND month < ?""", (syear, smonth, emonth)):
            l_diary.append(
                diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6],
                            row[7], row[8], row[0]))

        for row in cur.execute(
                """SELECT * FROM diary WHERE
                                  year == ?
                                  AND month == ?
                                  AND day <= ?""", (eyear, emonth, eday)):
            l_diary.append(
                diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6],
                            row[7], row[8], row[0]))

    if syear < eyear:
        for row in cur.execute(
                """SELECT * FROM diary WHERE
                                  (year == ?
                                  AND month == ?
                                  AND day >= ?)
                                  OR
                                  (year == ?
                                   AND month > ?)
                                  OR
                                  (year > ?
                                   AND year < ?)
                                  OR
                                  (year == ?
                                   AND month < ?)
                                  OR
                                  (year == ?
                                   AND month == ?
                                   AND day <= ?)""",
            (syear, smonth, sday, syear, smonth, syear, eyear, eyear, emonth,
             eyear, emonth, eday)):
            l_diary.append(
                diary.Diary(row[1], row[2], row[3], row[4], row[5], row[6],
                            row[7], row[8], row[0]))

    conn.close()
    return l_diary
示例#11
0
    def setUp(self):

        # create a temporary diary for each test
        copyfile(diaryFileName, tempDiaryFileName)

        self.diary = d.Diary(tempDiaryFileName)