Subversion Repositories SmartDukaan

Rev

Rev 16436 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16436 Rev 16439
Line 8... Line 8...
8
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
8
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
9
from sqlalchemy.sql import func
9
from sqlalchemy.sql import func
10
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
10
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
11
    between
11
    between
12
 
12
 
13
PUSH_NOTIFICATIONS_RETRY_SQL ="select  x.user_id, x.id, x.created, x.notification_campaign_id, x.name, TIMESTAMPDIFF(HOUR, x.created, x.expiresat) tdiff, x.sent-IF (y.received is null, 0, y.received) failureCount, x.last_active, x.expiresat from (select p.id,p.user_id, p.created, p.notification_campaign_id, n.name, count(*) sent, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' or name not like '%copy%')) and p.type='sent' and p.message = 'success' and ua.last_active >= p.created and ua.last_active <= n.expiresat group by p.id) as x left join (select p.id, p.user_id, p.created, p.notification_campaign_id, n.name, count(*) received, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' or name not like '%copy%')) and p.type='recieved' group by p.id) as y on (x.user_id = y.user_id and x.notification_campaign_id = y.notification_campaign_id) having failureCount =1"
13
PUSH_NOTIFICATIONS_RETRY_SQL ="select  x.user_id, x.id, x.created, x.notification_campaign_id, x.name, TIMESTAMPDIFF(HOUR, x.created, x.expiresat) tdiff, x.sent-IF (y.received is null, 0, y.received) failureCount, x.last_active, x.expiresat from (select p.id,p.user_id, p.created, p.notification_campaign_id, n.name, count(*) sent, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id join (select * from (select * from devices order by id desc) dev group by user_id) d on p.user_id = d.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' and name not like '%copy%')) and p.type='sent' and p.message = 'success' and d.versioncode >=14 and ua.last_active >= p.created and ua.last_active <= n.expiresat group by p.id) as x left join (select p.id, p.user_id, p.created, p.notification_campaign_id, n.name, count(*) received, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id join (select * from (select * from devices order by id desc) dev group by user_id) d on p.user_id = d.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' and name not like '%copy%')) and d.versioncode >=14 and p.type='recieved' group by p.id) as y on (x.user_id = y.user_id and x.notification_campaign_id = y.notification_campaign_id) having failureCount =1"
14
 
14
 
15
db = MySQLdb.connect('localhost',"root","shop2020","dtr" )
15
db = MySQLdb.connect('localhost',"root","shop2020","dtr" )
16
cursor = db.cursor()
16
cursor = db.cursor()
17
DataService.initialize(db_hostname="localhost")
17
DataService.initialize(db_hostname="localhost")
18
 
18