Exemplo n.º 1
0
            "SELECT * FROM timesheet WHERE ({}) ORDER BY checkin".format(
                query), values))

    def poll(s, period, user, software, file, status, note=""):
        """ Poll the database to show activity """
        with s:
            return s.write(None, timestamp.now(), UUID, period, user, software,
                           file, status, note)

    def read_all(s):
        """ Quick way to grab all data from the database """
        with s:
            for row in s.read("id != 0"):
                yield row


if __name__ == '__main__':
    import test
    import os
    with test.temp(".db") as f:
        os.unlink(f)
        db = DB(f)
        assert list(db.read_all()) == []
        # Add entries
        db.poll(1, "me", "python", "path/to/file", "active", "first entry")
        db.poll(1, "you", "python", "path/to/file", "idle", "second entry")
        db.poll(1, "us", "python", "path/to/file", "active", "last entry")
        res = list(db.read_all())
        assert len(res) == 3
        assert len(res[0]) == len(db.struct)
Exemplo n.º 2
0
        return s._note

    def set_path(s, val):
        s.set_var("_path", val)

    def get_path(s):
        return s._path

    def get_status(s):
        return s._active


if __name__ == '__main__':
    import test
    import os
    with test.temp(".db") as tmp:
        os.unlink(tmp)
        mon = Monitor("python", "ME!", tmp)
        mon._period = 1  # speed period to one second
        mon.set_note("HI THERE")
        mon.set_path("path/to/file")
        print("Polling please wait...")
        mon.start()
        time.sleep(1)  # One active
        mon.checkin()
        time.sleep(2)  # One active, one idle
        mon.stop()
        curr = timestamp.now()
        res = list(mon.query(curr - 10, curr))
        assert len(res) == 2
        assert res[0]["file"] == "path/to/file"
Exemplo n.º 3
0
        curr_table = assets.Table(ord_current_stamps)

        ass = assets.Assets()
        ass.view(title=title,
                 plot1=curr_data,
                 table=curr_table,
                 comp=timestamp.datetime.datetime.now().strftime(
                     "Created on %a %m %Y %M:%S"))


if __name__ == '__main__':
    import os
    import test
    import time
    from pprint import pprint
    with test.temp() as tmp:
        os.unlink(tmp)
        tmp_db = db.DB(tmp)
        tmp_db.poll(1, "me", "python", "path/to/file", "active", "first entry")
        tmp_db.poll(1, "you", "python", "path/to/file", "idle", "second entry")
        tmp_db.poll(1, "us", "python", "path/to/file", "active", "third entry")
        tmp_db.poll(1, "us", "python", "path/to/file", "active", "third entry")
        disp = Display(tmp)
        # res = disp.query(time.time() - 10.0, time.time() + 10.0)
        # pprint(res)
        # pprint(disp.rearrange("note", res))
        # pprint(disp.parse_note(time.time() - 10.0, time.time() + 10.0))

        # for session in res:
        #     assert len(res[session]) == 2
        # pprint.pprint(res[session])