def setApplication(self, application_key, json): session = models.getSession() application = session.query(models.Application).filter_by(key=application_key).first() if application: models.updateObjectWithJSON(application, json, ['key']) session.commit() return application
def getApplicationSecret(self, application_key): session = models.getSession() application = session.query(models.Application).filter_by(key = application_key).first() if application != None: return application.secret return None
def updateGood(self, good_key, json): session = models.getSession() good = session.query(models.Good).filter_by(key=good_key).first() if good: models.updateObjectWithJSON(good, json, ['key', 'application_key']) session.commit() return good
def exportFile(self, application, fromDate, toDate, file): session = models.getSession() q = session.query(models.Events).filter(models.Events.application_key==application, models.Events.created>=fromDate, models.Events.created<toDate) for row in q: file.write(extras.toJSON(row.as_dict())+'\n') file.flush()
def addPrices(self, application_key, engine, data, path): session = models.getSession() prices = models.Prices(application_key = application_key, engine=engine, data=data, path=path) pricing.PricingEngine.validate(prices) session.add(prices) session.commit() return prices
def setABTest(self, application_key, json): session = models.getSession() abtest = self.getABTest(application_key) if abtest: newABTest = models.ABTest() newABTest.application_key = abtest.application_key newABTest.countryWhiteList = abtest.countryWhiteList newABTest.countryBlackList = abtest.countryBlackList newABTest.modulus = abtest.modulus newABTest.modulusLimit = abtest.modulusLimit newABTest.groupAPrices_key = abtest.groupAPrices_key newABTest.groupBPrices_key = abtest.groupBPrices_key # Check price foreign keys manually for prices in ['groupAPrices_key', 'groupBPrices_key']: if prices in json and json[prices] != None: count = session.query(models.Prices).join(models.Application).filter(models.Application.key == newABTest.application_key).filter(models.Prices.key==json[prices]).count() if count == 1: pass else: del json[prices] models.updateObjectWithJSON(newABTest, json, ['key']) session.add(newABTest) session.commit() return newABTest
def getGood(self, key): session = models.getSession() good = session.query(models.Good).filter_by(key=key).first() cacheObject(good) session.close() return good
def deleteGood(self, good_key): session = models.getSession() res = session.query(models.Good).filter_by(key=good_key).delete() session.commit() session.close() return res
def getPrice(self, prices_key): session = models.getSession() price = session.query(models.Prices).filter_by(key=prices_key).first() cacheObject(price) session.close() return price
def getApplicationExists(self, application_key): session = models.getSession() app = session.query( models.Application).filter_by(key=application_key).count() session.close() return app
def setMetrics(self, application_key, json): session = models.getSession() metrics = session.query(models.Metrics).join(models.Application).filter(models.Application.key == application_key).first() if metrics: models.updateObjectWithJSON(metrics, json, ['key']) session.commit() return metrics
def setCurrency(self, application_key, json): session = models.getSession() currencies = session.query(models.Currencies).join(models.Application).filter_by(key=application_key).first() if currencies: models.updateObjectWithJSON(currencies, json, ['key']) session.commit() return currencies
def getGoods(self, application_key): session = models.getSession() goods = session.query(models.Good).join(models.Application).filter( models.Application.key == application_key).all() cacheObjects(goods) session.close() return goods
def getPrices(self, application_key): session = models.getSession() prices = session.query(models.Prices).join(models.Application).filter( models.Application.key == application_key).all() cacheObjects(prices) session.close() return prices
def getABTest(self, application_key): session = models.getSession() abtests = session.query(models.ABTest).join(models.Application).filter(models.Application.key == application_key).order_by(models.ABTest.id.desc()).limit(1).all() if len(abtests) == 1: return abtests[0] return None
def deleteApplication(self, application_key): session = models.getSession() res = session.query( models.Application).filter_by(key=application_key).delete() session.commit() session.close() return res
def getCurrency(self, application_key): session = models.getSession() currency = session.query(models.Currencies).join( models.Application).filter_by(key=application_key).first() cacheObject(currency) session.close() return currency
def getApplications(self): session = models.getSession() applications = session.query(models.Application).all() cacheObjects( applications, ['currencies', 'abtest', 'events', 'metrics', 'goods', 'prices']) session.close() return applications
def getApplicationWithName(self, name): session = models.getSession() app = session.query(models.Application).filter_by(name=name).first() cacheObject( app, ['currencies', 'abtest', 'events', 'metrics', 'goods', 'prices']) session.close() return app
def getMetrics(self, application_key): session = models.getSession() metrics = session.query(models.Metrics).join( models.Application).filter( models.Application.key == application_key).first() if metrics: cacheObject(metrics) session.close() return metrics
def exportFile(self, application, fromDate, toDate, file): session = models.getSession() q = session.query(models.Events).filter( models.Events.application_key == application, models.Events.created >= fromDate, models.Events.created < toDate, ) for row in q: file.write(extras.toJSON(row.as_dict()) + "\n") file.flush()
def getApplicationSecret(self, application_key): session = models.getSession() application = session.query( models.Application).filter_by(key=application_key).first() if application != None: session.close() return application.secret session.close() return None
def updateGood(self, good_key, json): session = models.getSession() good = session.query(models.Good).filter_by(key=good_key).first() if good: models.updateObjectWithJSON(good, json, ['key', 'application_key']) session.commit() cacheObject(good) session.close() return good
def addGood(self, application_key, name): session = models.getSession() application = session.query(models.Application).filter_by(key = application_key).first() good = models.Good(name=name, application_key=application.key) session.add(good) session.commit() return good
def exportStream(self, application, fromDate, toDate, file = None): session = models.getSession() q = session.query(models.Events).filter(models.Events.application_key==application, models.Events.created>=fromDate, models.Events.created<toDate) for row in q: if file == None: yield extras.toJSON(row.as_dict())+'\n' else: file.write(extras.toJSON(row.as_dict())+'\n')
def setApplication(self, application_key, json): session = models.getSession() application = session.query( models.Application).filter_by(key=application_key).first() if application: models.updateObjectWithJSON(application, json, ['key']) session.commit() cacheObject(application) session.close() return application
def setCurrency(self, application_key, json): session = models.getSession() currencies = session.query(models.Currencies).join( models.Application).filter_by(key=application_key).first() if currencies: models.updateObjectWithJSON(currencies, json, ['key']) session.commit() cacheObject(currencies) session.close() return currencies
def addPrices(self, application_key, engine, data, path): session = models.getSession() prices = models.Prices(application_key=application_key, engine=engine, data=data, path=path) pricing.PricingEngine.validate(prices) session.add(prices) session.commit() cacheObject(prices) session.close() return prices
def setMetrics(self, application_key, json): session = models.getSession() metrics = session.query(models.Metrics).join( models.Application).filter( models.Application.key == application_key).first() if metrics: models.updateObjectWithJSON(metrics, json, ['key']) session.commit() cacheObject(metrics) session.close() return metrics
def addGood(self, application_key, name): session = models.getSession() application = session.query( models.Application).filter_by(key=application_key).first() good = models.Good(name=name, application_key=application.key) session.add(good) session.commit() cacheObject(good) session.close() return good
def exportStream(self, application, fromDate, toDate, file=None): session = models.getSession() q = session.query(models.Events).filter( models.Events.application_key == application, models.Events.created >= fromDate, models.Events.created < toDate, ) for row in q: if file == None: yield extras.toJSON(row.as_dict()) + "\n" else: file.write(extras.toJSON(row.as_dict()) + "\n")
def getABTest(self, application_key): session = models.getSession() abtests = session.query(models.ABTest).join(models.Application).filter( models.Application.key == application_key).order_by( models.ABTest.id.desc()).limit(1).all() if len(abtests) == 1: cacheObject(abtests[0]) session.close() return abtests[0] session.close() return None
def addApplication(self, name): session = models.getSession() application = models.Application(name=name) currencies = models.Currencies(application=application) abtest = models.ABTest(application=application) metrics = models.Metrics(application=application) session.add(application) session.add(currencies) session.add(abtest) session.add(metrics) session.commit() return application
def deletePrices(self, prices_key): session = models.getSession() prices = session.query(models.Prices).filter_by(key = prices_key).first() prices.data = None prices.path = None prices.deleted = True abtest = self.getABTest(prices.application_key) if abtest.groupAPrices_key == prices_key and abtest.groupBPrices_key != prices_key: self.setABTest(prices.application_key, {'groupAPrices_key': None}) elif abtest.groupAPrices_key != prices_key and abtest.groupBPrices_key == prices_key: self.setABTest(prices.application_key, {'groupBPrices_key': None}) elif abtest.groupAPrices_key == prices_key and abtest.groupBPrices_key == prices_key: self.setABTest(prices.application_key, {'groupAPrices_key': None, 'groupBPrices_key': None}) session.commit() return True
def addApplication(self, name): session = models.getSession() application = models.Application(name=name) currencies = models.Currencies(application=application) abtest = models.ABTest(application=application) metrics = models.Metrics(application=application) session.add(application) session.add(currencies) session.add(abtest) session.add(metrics) session.commit() cacheObject(application) session.close() return application
def processThreadUpdate(self, filenames): session = models.getSession() eventsCount = 0 events = [] for filename in filenames: if 'json' in filename: try: data = self.storage.load(filename) data = json.loads(data) except: monitor.getMonitor().count('AnalyticsUpdateBadParse') try: self.storage.delete(filename) except: monitor.getMonitor().count('AnalyticsUpdateBadDelete') continue if self.getApplication(data['liftpass-application']) != None: currentEvents = self.processUpdate(data) eventsCount += len(currentEvents) events.extend(currentEvents) self.storage.delete(filename) if len(events) > 1000: print('Saving: %s saved %d (%d so far)'%(multiprocessing.current_process(), len(events), eventsCount)) session.bulk_insert_mappings(models.Events, events) events = [] session.bulk_insert_mappings(models.Events, events) session.commit() return eventsCount
def setABTest(self, application_key, json): session = models.getSession() abtest = self.getABTest(application_key) if abtest: newABTest = models.ABTest() newABTest.application_key = abtest.application_key newABTest.countryWhiteList = abtest.countryWhiteList newABTest.countryBlackList = abtest.countryBlackList newABTest.modulus = abtest.modulus newABTest.modulusLimit = abtest.modulusLimit newABTest.groupAPrices_key = abtest.groupAPrices_key newABTest.groupBPrices_key = abtest.groupBPrices_key # Check price foreign keys manually for prices in ['groupAPrices_key', 'groupBPrices_key']: if prices in json and json[prices] != None: count = session.query(models.Prices).join( models.Application).filter( models.Application.key == newABTest.application_key ).filter(models.Prices.key == json[prices]).count() if count == 1: pass else: del json[prices] models.updateObjectWithJSON(newABTest, json, ['key']) session.add(newABTest) session.commit() cacheObject(newABTest) session.close() return newABTest
def deletePrices(self, prices_key): session = models.getSession() prices = session.query(models.Prices).filter_by(key=prices_key).first() prices.data = None prices.path = None prices.deleted = True abtest = self.getABTest(prices.application_key) if abtest.groupAPrices_key == prices_key and abtest.groupBPrices_key != prices_key: self.setABTest(prices.application_key, {'groupAPrices_key': None}) elif abtest.groupAPrices_key != prices_key and abtest.groupBPrices_key == prices_key: self.setABTest(prices.application_key, {'groupBPrices_key': None}) elif abtest.groupAPrices_key == prices_key and abtest.groupBPrices_key == prices_key: self.setABTest(prices.application_key, { 'groupAPrices_key': None, 'groupBPrices_key': None }) session.commit() session.close() return True
def processThreadUpdate(self, filenames): session = models.getSession() eventsCount = 0 events = [] for filename in filenames: if "json" in filename: try: data = self.storage.load(filename) data = json.loads(data) except: monitor.getMonitor().count("AnalyticsUpdateBadParse") try: self.storage.delete(filename) except: monitor.getMonitor().count("AnalyticsUpdateBadDelete") continue if self.getApplication(data["liftpass-application"]) != None: currentEvents = self.processUpdate(data) eventsCount += len(currentEvents) events.extend(currentEvents) self.storage.delete(filename) if len(events) > 1000: print("Saving: %s saved %d (%d so far)" % (multiprocessing.current_process(), len(events), eventsCount)) session.bulk_insert_mappings(models.Events, events) events = [] session.bulk_insert_mappings(models.Events, events) session.commit() return eventsCount
def getCurrency(self, application_key): session = models.getSession() return session.query(models.Currencies).join(models.Application).filter_by(key=application_key).first()
def getApplication(self, application_key): return models.getSession().query(models.Application).filter_by(key=application_key).first()
def getApplications(self): return models.getSession().query(models.Application).all()
def getMetrics(self, application_key): session = models.getSession() return session.query(models.Metrics).join(models.Application).filter(models.Application.key == application_key).first()
def deleteApplication(self, application_key): session = models.getSession() res = session.query(models.Application).filter_by(key=application_key).delete() session.commit() return res
def deleteGood(self, good_key): session = models.getSession() res = session.query(models.Good).filter_by(key=good_key).delete() session.commit() return res
def getGood(self, key): session = models.getSession() return session.query(models.Good).filter_by(key = key).first()
def getGoods(self, application_key): session = models.getSession() return session.query(models.Good).join(models.Application).filter(models.Application.key == application_key).all()
def getPrice(self, prices_key): session = models.getSession() return session.query(models.Prices).filter_by(key = prices_key).first()