コード例 #1
0
ファイル: datasetpage.py プロジェクト: philippkraft/odmf
 def multirecords_csv(self,
                      valuetype=None,
                      user=None,
                      site=None,
                      date=None,
                      instrument=None,
                      type=None,
                      level=None,
                      onlyaccess=False,
                      witherrors=False):
     web.setmime('text/csv')
     session = db.scoped_session()
     datasets = self.subset(session, valuetype, user, site, date,
                            instrument, type, level, onlyaccess)
     datagroup = db.DatasetGroup([ds.id for ds in datasets])
     st = io.BytesIO()
     st.write(codecs.BOM_UTF8)
     st.write(('"Dataset","ID","time","{vt} calibrated","{vt} raw",' +
               '"site","comment","is error?"\n').format(
                   vt=ds.valuetype).encode('utf-8'))
     for r in datagroup.iterrecords(session, witherrors):
         d = dict(c=(str(r.comment).replace('\r', '').replace('\n', ' / '))
                  if r.comment else '',
                  vc=r.value if witherrors and not r.is_error else '',
                  vr=r.rawvalue,
                  time=web.formatdate(r.time) + ' ' +
                  web.formattime(r.time),
                  id=r.id,
                  ds=ds.id,
                  s=ds.site.id,
                  e=int(r.is_error))
         st.write(('{ds:i},{id:i},{time},{vc:s0,{vr:s},{s:i},' +
                   '"{c}",{e}\n').format(**d).encode('utf-8'))
     session.close()
     return st.getvalue()
コード例 #2
0
    def draw(self, figure):
        """
        Draws the subplot on a matplotlib figure
        """
        ax = figure.axes[self.position - 1]
        plt.sca(ax)
        for l in self.lines:
            l.draw(ax, self.plot.startdate, self.plot.enddate)
        if self.ylim:
            if np.isfinite(self.ylim[0]):
                plt.ylim(ymin=self.ylim[0])
            if np.isfinite(self.ylim[1]):
                plt.ylim(ymax=self.ylim[1])

        # Show log book entries for the logsite of this subplot

        # Get all site-ids of this subplot
        sites = self.get_sites()
        # Draw only logs if logsite is a site of the subplot's lines
        if self.logsite in sites:
            # open session - trying the new scoped_session
            session = db.scoped_session()
            # Get logbook entries for logsite during the plot-time
            logs = session.query(db.Log).filter_by(_site=self.logsite).filter(
                db.Log.time >= self.plot.startdate).filter(
                    db.Log.time <= self.plot.enddate)
            # Traverse logs and draw them
            for log in logs:
                x = plt.date2num(log.time)
                plt.axvline(x,
                            linestyle='-',
                            color='r',
                            alpha=0.5,
                            linewidth=3)
                plt.text(x,
                         plt.ylim()[0],
                         log.type,
                         ha='left',
                         va='bottom',
                         fontsize=8)
        plt.xlim(date2num(self.plot.startdate), date2num(self.plot.enddate))
        plt.xticks(rotation=15)
        ax.yaxis.set_major_locator(MaxNLocator(prune='upper'))
        ax.tick_params(axis='both', which='major', labelsize=8)

        ax.grid()
        ax.legend(loc=0, prop=dict(size=9))
        if self.lines:
            l = self.lines[0]
            plt.ylabel('%s [%s]' % (l.valuetype.name, l.valuetype.unit),
                       fontsize=self.plot.args.get('ylabelfs', 'small'))
コード例 #3
0
ファイル: datasetpage.py プロジェクト: philippkraft/odmf
 def records(self,
             dataset,
             mindate,
             maxdate,
             minvalue,
             maxvalue,
             threshold=None,
             limit=None):
     """
     Returns a html-table of filtered records
     TODO: This method should be replaced by records_json. 
     Needs change in datasettab.html to create DOM elements using 
     jquery from the delivered JSON
     """
     session = db.scoped_session()
     ds = session.query(db.Dataset).get(int(dataset))
     records = ds.records.order_by(
         db.Record.time).filter(~db.Record.is_error)
     tstart = web.parsedate(mindate.strip(), raiseerror=False)
     tend = web.parsedate(maxdate.strip(), raiseerror=False)
     threshold = web.conv(float, threshold)
     limit = web.conv(int, limit, 250)
     try:
         if threshold:
             records = ds.findjumps(float(threshold), tstart, tend)
             currentcount = None
             totalcount = None
         else:
             if tstart:
                 records = records.filter(db.Record.time >= tstart)
             if tend:
                 records = records.filter(db.Record.time <= tend)
             if minvalue:
                 records = records.filter(db.Record.value > float(minvalue))
             if maxvalue:
                 records = records.filter(db.Record.value < float(maxvalue))
             totalcount = records.count()
             records = records.limit(limit)
             currentcount = records.count()
     except:
         return web.Markup('<div class="error">' + traceback() + '</div>')
     res = web.render('record.html',
                      records=records,
                      currentcount=currentcount,
                      totalrecords=totalcount,
                      dataset=ds,
                      actionname="split dataset",
                      action="/dataset/setsplit",
                      action_help='/wiki/dataset/split').render('xml')
     session.close()
     return res
コード例 #4
0
def create(message):
    """Adds a health_check to the DB and queues it for upload

    Args:
        message (str): The message of the health_check
    """
    with scoped_session() as session:
        # Insert the health_check into the DB
        health_check = HealthCheck()
        health_check.message = message

        session.add(health_check)
        session.commit()

        # Return the health_check ID so that the caller can track its progress
        _id = health_check.id

    return get(_id)
コード例 #5
0
ファイル: datasetpage.py プロジェクト: philippkraft/odmf
 def records_json(self,
                  dataset,
                  mindate=None,
                  maxdate=None,
                  minvalue=None,
                  maxvalue=None,
                  threshold=None,
                  limit=None,
                  witherror=False):
     """
     Returns the records of the dataset as JSON
     """
     with db.scoped_session() as session:
         ds = session.query(db.Dataset).get(int(dataset))
         if web.user.current.level < ds.access:  # @UndefinedVariable
             raise cherrypy.HTTPError(
                 403, 'User privileges not sufficient to access ds:' +
                 str(dataset))
         records = ds.records.order_by(db.Record.time)
         if witherror:
             records = records.filter(~db.Record.is_error)
         tstart = web.parsedate(mindate.strip(), raiseerror=False)
         tend = web.parsedate(maxdate.strip(), raiseerror=False)
         threshold = web.conv(float, threshold)
         limit = web.conv(int, limit, 250)
         try:
             if threshold:
                 records = ds.findjumps(float(threshold), tstart, tend)
             else:
                 if tstart:
                     records = records.filter(db.Record.time >= tstart)
                 if tend:
                     records = records.filter(db.Record.time <= tend)
                 if minvalue:
                     records = records.filter(
                         db.Record.value > float(minvalue))
                 if maxvalue:
                     records = records.filter(
                         db.Record.value < float(maxvalue))
                 records = records.limit(limit)
         except:
             raise cherrypy.HTTPError(500, traceback())
         return web.as_json({'error': None, 'data': records.all()})