File tree Expand file tree Collapse file tree 6 files changed +874
-0
lines changed Expand file tree Collapse file tree 6 files changed +874
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,37 @@ source file:
7575
7676 pixel_x, pixel_y = get_pixel_coords()
7777
78+ factdb
79+ ------
80+
81+ This module contains ``peewee `` ``Models `` for our ``factdata `` MySQL database.
82+ These were automatically created by ``peewee `` and provide means to query this database in python without writing raw sql queries.
83+
84+ For example, to get the total number of runs take by FACT you can do:
85+
86+ .. code :: python
87+
88+ from fact.factdb import connect_database, RunInfo
89+
90+ connect_database() # this uses the credentials module if no config is given
91+
92+ num_runs = RunInfo.select().count()
93+
94+ A few convenience functions are already implemented.
95+ To get a ``pandas.DataFrame `` containing the observation time per source and runtype, you can do:
96+
97+
98+ .. code :: python
99+
100+ from fact.factdb import connect_database, get_ontime_per_source_and_runtype
101+
102+ connect_database()
103+
104+ num_runs = RunInfo.select().count()
105+ print (get_ontime_by_source_and_runtype())
106+
107+
108+
78109 auxservices
79110-----------
80111
Original file line number Diff line number Diff line change 1+ from .database import factdata_db
2+ from .utils import get_ontime_by_source , get_ontime_by_source_and_runtype
3+ from .models import *
Original file line number Diff line number Diff line change 1+ from peewee import MySQLDatabase
2+ import wrapt
3+ from ..credentials import get_credentials
4+
5+ factdata_db = MySQLDatabase (None )
6+
7+
8+ def connect_database (config = None ):
9+ if config is None :
10+ config = get_credentials ()['database' ]
11+ factdata_db .init (** config )
12+ factdata_db .connect ()
You can’t perform that action at this time.
0 commit comments