a +Ag@sddlmZddlmZmZmZddlmZmZddlm Z m Z ddl m Z ddl mZddlmZe aGdd d tZGd d d ZGd d d eZdS))Config) create_engineinspectdesc)ColumnString)DATEJSONB)declarative_base)SQLAlchemyError) sessionmakerc@s0eZdZejZededddZede ddZ dS)MonthlyStatsState sending_dateFT)indexZ primary_keyinfo)rN) __name__ __module__ __qualname__rMONTHLYSTATS_TABLENAMEZ __tablename__rrrr datarrA/home/cmiss/Jenkins/workspace/SPARC-API-DEV/scripts/monthly_db.pyr sr c@s6eZdZddZddZddZd dd Zd d Zd S)TablecCs.t|}tj|t|}||_||_dSN)rbasemetadataZ create_allr _session_state)self databaseURLstatedbSessionrrr__init__s  zTable.__init__cCs|j|j}|Sr)rqueryrcount)rrowsrrrgetNumberOfRowszTable.getNumberOfRowcCs^z:|j|jt|jjd}|r2|WSWdSWntyX|j YdS0dS)N) rr$rZorder_byrrlimitallr Zrollback)rresultrrrpullLatestDates&   zTable.pullLatestDateFcCsJ|j||d}|j||rFz|jWntyD|jYn0dS)N)rr)rraddcommitr _s)rdateIninputr.ZnewStaterrr pushState+s  zTable.pushStatecCsR|dkrdS|}|rN|dj}|j|jksJ|j|jkrN|j|jkrNdSdS)NrTF)r'r,ryearmonth)rr0Z recordDateZlastDaterrrsendingRequired6s     zTable.sendingRequiredN)F)rrrr#r'r,r2r5rrrrrs  rc@seZdZddZdS)MonthlyStatsTablecCst||tdSr)rr#r )rrrrrr#EszMonthlyStatsTable.__init__N)rrrr#rrrrr6Dsr6N) app.configrZ sqlalchemyrrrrrZsqlalchemy.dialects.postgresqlrr Zsqlalchemy.ext.declarativer Zsqlalchemy.excr Zsqlalchemy.ormr rr rr6rrrrs    2