Created
November 4, 2015 10:58
-
-
Save riceluxs1t/601e336a9f64b8a3232e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from billi.redis_utils import get_redis, KEY_DAILY_ACTIVE_USER | |
from django.contrib.auth.models import User | |
from billi.utils import from_string_to_utc, utcnow, from_utc_to_local | |
from dateutil.rrule import rrule, DAILY | |
import binascii | |
from billi.settings import BILLI_DEFAULT_TIMEZONE_OFFSET, BILLI_DEFAULT_TIMEZONE | |
import logging | |
from datetime import timedelta | |
from mobile_user.models import Mobile_User | |
from optparse import make_option | |
from reward.models import UnifyAccount, ImpressionAccount | |
logger = logging.getLogger(__name__) | |
def bit_and_two_strings(me, you): | |
return ''.join(chr(ord(a) & ord(b)) for a,b in zip(me,you)) | |
r = get_redis() | |
date = '2015-10-30' | |
dau_key = KEY_DAILY_ACTIVE_USER + ':' + date | |
dau_key_string = r.get(dau_key) | |
october_string = dau_key_string | |
october_user = [] | |
for i in xrange(len(dau_key_string)): | |
chunk = int(binascii.hexlify(dau_key_string[i]),16) | |
for j in [7, 6, 5, 4, 3, 2, 1, 0]: | |
if chunk & 2**j: | |
october_user.append((i*8) + 7-j) | |
date = '2015-11-01' | |
dau_key = KEY_DAILY_ACTIVE_USER + ':' + date | |
dau_key_string = r.get(dau_key) | |
november_user = [] | |
november_string = dau_key_string | |
for i in xrange(len(dau_key_string)): | |
chunk = int(binascii.hexlify(dau_key_string[i]),16) | |
for j in [7, 6, 5, 4, 3, 2, 1, 0]: | |
if chunk & 2**j: | |
november_user.append((i*8) + 7-j) | |
total_bitmap = bit_and_two_strings(november_string, october_string) | |
total_user = [] | |
for i in xrange(len(total_bitmap)): | |
chunk = int(binascii.hexlify(total_bitmap[i]),16) | |
for j in [7, 6, 5, 4, 3, 2, 1, 0]: | |
if chunk & 2**j: | |
total_user.append((i*8) + 7-j) | |
for user in total_user: | |
if user not in october_user or user not in november_user: | |
print "you did something wrong!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment