Esempio n. 1
0
 def get_inadefinfo(nr):
     number = int(nr)
     maindir = inaconf.maindir
     params = inafiles.getmaildata()
     locname = inafiles.getclearloc(inaconf.get_camlocations(), number)
     return {'login': params['mail'] % (number), 'pwd': params['pwd'] % (number), 'name': 'Inadef Cam %d-%s' % (number, locname[0]),
             'rec': inafiles.get_cam_receipients(number), 'host': params['host'], 'outhost': params['outhost']}
Esempio n. 2
0
def getmeteoforcam(camnr):
    nr = int(camnr)
    locdata = inafiles.getlocationdata(inaconf.get_camlocations(), nr)
    locnr = int(locdata[1])
    summary = pd.DataFrame(getsummary(locnr))
    print(summary)
    return summary
Esempio n. 3
0
def get_camdir(camnr):
    maindir = inaconf.maindir
    loc = getlocationdata(inaconf.get_camlocations(), camnr)
    for thing in os.listdir(maindir):
        if os.path.isdir(os.path.join(
                maindir,
                thing)) and thing[0:7] == 'cam_%d_%d' % (loc[1], camnr):
            return os.path.join(maindir, thing)
Esempio n. 4
0
def dirlocationchange():
    maindir = inaconf.maindir
    locations = inaconf.get_camlocations()
    for thing in os.listdir(maindir):
        if os.path.isdir(os.path.join(maindir,
                                      thing)) and thing[0:4] == 'cam_':
            camnr = int(os.path.basename(thing)[6])
            camloc, locnr = getloc(locations, camnr)
            newname = 'cam_%s_%d%s' % (locnr, camnr, camloc)
            if newname != thing:
                try:
                    os.rename(os.path.join(maindir, thing),
                              os.path.join(maindir, newname))
                    print('renamed directory %s to %s' %
                          (os.path.join(maindir, thing), newname))
                except:
                    print('can' 't rename right now. Will try later.')
Esempio n. 5
0
    def send_mails(camnr):
        i = int(camnr)
        alerts, cautions, batts, gaps, meteodata, current = inamailer.alerts[i], inamailer.cautions[i], inamailer.batts[i], inamailer.gaps[i], inamailer.meteodata[i], inamailer.current[i]
        locations = inaconf.get_camlocations()
        locname = inafiles.getclearloc(locations, i)[0]
        locnr = int(inafiles.getclearloc(locations, i)[1])
        currenttext = 'Current Images (last %d days):\n'%(inaconf.lastn)
        for cur in current:
            currenttext = currenttext+'\nFile %s (%s)'%(cur['file'], cur['date'].strftime(inaconf.datehumanfmt))
        attachments = []
        for loc in inamailer.locplots[locnr]:
            attachments.append(loc['plotfile'])
        reportname = 'Inadef report (%s), %s'%(locname, datetime.now().strftime(inaconf.datehumanfmt))
        subjectmode = 'Notification: '
        alerttext ='\n\nReflector alerts:'
        gaptext='\nGaps:'
        if len(gaps)>0:
            subjectmode = 'Alert! '
            gaptext = 'Alert: Camera not delivering images at expected frequency (1 image/24h)'
        for gap in gaps:
            gaptext = gaptext + '\nUnexpected gap: img %s - %s'% (gap['prevdate'].strftime(inaconf.datehumanfmt), gap['date'].strftime(inaconf.datehumanfmt))
        for alert in alerts:
            date, time = inafiles.read_timedate_from_filename(alert[1])
            attachments = attachments+alerts[2]
            camstr = inafiles.getclearloc(locations, i)
            text = 'Alert: Cam %d (%s) - on %s reflector presumably missing! See attachment.'%(i, camstr[0], camdate.strftime(inaconf.datelogfmt))
            alerttext = alerttext + '\n' + text
            subjectmode = 'Alert! '
        cautiontext='\n\nReflector cautions:'
        for caution in cautions:
            date = inafiles.datetime_from_file(caution[2][0])
            attachments = attachments+caution[2]
            camstr = inafiles.getclearloc(locations, i)
            text = 'caution: Cam %d (%s) - on %s reflector not clearly detected. See attachment.'%(i, camstr[0], date.strftime(inaconf.datehumanfmt))
            cautiontext = cautiontext + '\n' + text
        meteotext ='\n\nMeteorological station data:'
        if len (meteodata)>0:
            avg = meteodata['total'].mean()
            first = meteodata['start'].min().strftime(inaconf.datehumanfmt)
            last = meteodata['end'].max().strftime(inaconf.datehumanfmt)

            devices = ';'.join(meteodata['device'])
            meteotext = meteotext+'\n%s: total precipitation - %.1f mm from %s - %s'%(devices, avg, first, last)
            for device  in meteodata.iterrows():
                meteotext = meteotext+'\nBattery level last 24h (%s): %.f percent'%(device[1]['device'], device[1]['batt'])
        tlctext =''
        relevanttlc = []
        if len(inamailer.tlcdata) > 0:
            tlctext = '\n\nTimelapse Camera data:'
            relevanttlc = inamailer.tlcdata.loc[inamailer.tlcdata['location']==locnr]

            for rel in relevanttlc.iterrows():
                tlctext = tlctext + '\nCam "%s" read and refreshed on %s'%(rel[1]['direction'], rel[1]['refreshdate'].strftime(inaconf.datehumanfmt))
        tlcs = inafiles.readtlc()
        tlcs = tlcs.loc[tlcs['location']==locnr]

        for tlc in tlcs.iterrows():
            lastrefresh = datetime(2020,1,1)

            if len(relevanttlc) > 0:
                relevantentries = relevanttlc.loc[relevanttlc['tlcid']==tlc[1]['tlcid']]
                if len(relevantentries)>0:
                    lastrefresh = relevantentries['refreshdate'].max()
                runningfordays = (datetime.now() - lastrefresh.replace(tzinfo=None)).days
            else: runningfordays = 1000
            tlctext = tlctext + '\n\nTLC Running time since last refresh:'
            tlctext = tlctext + '\nCam "%s - %s": %d days' % (locname, tlc[1]['direction'], runningfordays)



        batttext = '\n\nTrailcam Battery data:'
        if batts[len(batts)-1][0] <= inaconf.battwarning:
            camstr = inafiles.getclearloc(locations, i)
            batttext = 'Battery notification: Level of cam %d (%s) low - last reading below %.f percent'%(i, camstr[0], 100*inaconf.battwarning)
            subjectmode = 'Alert! '
        for j in range(len(batts)):
            batttext = '\n'.join([batttext, 'Level on %s: %.f percent'%(batts[j][1].strftime(inaconf.datehumanfmt), batts[j][0]*100)])



        mailtext = '\n'.join([currenttext, gaptext, alerttext,cautiontext, batttext, tlctext, meteotext])
        inamailer.send_inadefmail(camnr=camnr, text=mailtext, rec_name='Inadef mail checker', subject=subjectmode + reportname,
                        attachments=attachments, maindir=inaconf.maindir)