Exemplo n.º 1
0
 async def wod(ctx):
     activity_data = get_activity_data(ctx.guild.id)
     data = []
     for user, user_data in activity_data.items():
         for time, value in user_data:
             name = user.split("#")[0]
             data.append([name, pd.to_datetime(time, unit='s'), value])
     df = pd.DataFrame(data, columns=["name", "time", "time_spent"])
     df["time_spent"] = df["time_spent"].apply(lambda k: k / (60 * 60))
     df = df.groupby(["time", "name"])[
         "time_spent"].sum().unstack()
     df = df.cumsum().filter(items=df.sum().nlargest(10).index)
     df = df.interpolate(method="time")
     ax = df.plot(title="Wasted on Discord")
     for label in ax.get_xticklabels():
         label.set_rotation(25)
         label.set_horizontalalignment('right')
     plt.ylabel("Hours")
     plt.xlabel("Day")
     locator = mdates.AutoDateLocator()
     formatter = mdates.DateFormatter("%d-%m-%y")
     ax.xaxis.set_major_locator(locator)
     ax.xaxis.set_major_formatter(formatter)
     ax.legend(loc="upper left", title_fontsize="xx-small",
               fontsize="xx-small")
     plt.savefig(fname='ranking_plot')
     file_path = join(settings.BASE_DIR, "ranking_plot.png")
     file = discord.File(file_path, filename="ranking_plot.png")
     await ctx.send(file=file)
Exemplo n.º 2
0
def single_chat(request,key):
    
    
    msgs = get_chat_messages(key)
    msgs_list = pagination(request,msgs,MESSAGES_PER_PAGE)
    
    dic = {'activity': get_activity_data(key),
                'chatmessages': msgs_list,
                'gps': Messages.objects.using('msgstore').exclude((Q(longitude = '0.0') | Q(latitude = '0.0'))),
                'media': Messages.objects.using('msgstore').exclude(media_url__isnull = True),
                'PAG_TITLE': 'Conversation'
                }
    return render_to_response('whatsapp/chat.html',dic,context_instance=RequestContext(request))
Exemplo n.º 3
0
def contact_profile(request, key):
    """
    Shows the contact profile
    """

    ret = {}

    ret['number'] = key.split('@')[0][2:]
    ret['jid'] = key
    ret['activity'] = get_activity_data(key)
    ret['whatsapp'] = 0

    ret['messages'] = Messages.objects.using('msgstore').filter(key_remote_jid=key).count()
    tstamp = Messages.objects.using('msgstore').filter(key_remote_jid=key).values('timestamp').order_by('timestamp')[0:1][0]['timestamp']
    ret['first_seen'] = timestamp2utc(float(tstamp) / 1000)
    tstamp = Messages.objects.using('msgstore').filter(key_remote_jid=key).values('timestamp').order_by('-timestamp')[0:1][0]['timestamp']
    ret['last_seen'] = timestamp2utc(float(tstamp) / 1000)
    ret['media_messages'] = Messages.objects.using('msgstore').filter(key_remote_jid=key).exclude(media_url__isnull=True).count()
    ret['gps_messages'] = Messages.objects.using('msgstore').filter(key_remote_jid=key).exclude((Q(longitude='0.0') | Q(latitude='0.0'))).count()

    # no wa_contacts table available
    if not 'wa_contacts' in connection.introspection.table_names():
        ret['name'] = 'Not in contacts'
        ret['status'] = 'N/A'
        if ret['messages'] > 0:
            ret['whatsapp'] = 1
    else:
        ret['name'] = WaContacts.objects.filter(jid=key).values('display_name')[0]['display_name']
        ret['whatsapp'] = WaContacts.objects.filter(jid=key).values('is_whatsapp_user')[0]['is_whatsapp_user']
        ret['status'] = WaContacts.objects.filter(jid=key).values('status')[0]['status']

    # if it's a group, get participants information
    peers = None
    if '-' in key:
        peers = []
        aux = Messages.objects.using('msgstore').filter(key_remote_jid=key).exclude(Q(remote_resource = '')).values('remote_resource').distinct()
        for peer in aux:
            peer = peer['remote_resource']
            if not 'wa_contacts' in connection.introspection.table_names():
                name = peer
            else:
                name = WaContacts.objects.filter(jid=peer).values('display_name')[0]
            
            count = Messages.objects.using('msgstore').filter(Q(key_remote_jid=key) & Q(remote_resource = peer)).count()
                
            peers.append({'id': peer , 'name': name , 'count': count})

    return render_to_response('whatsapp/profile.html', {'contact': ret, 'activity': ret['activity'] , 'peers': peers }, context_instance=RequestContext(request))
Exemplo n.º 4
0
def index(request):
    """
    Default view
    """

    try:
        wusers = WaContacts.objects.filter(is_whatsapp_user=1).count()
        nwusers = WaContacts.objects.filter(is_whatsapp_user=0).count()
        wasize = getsize(DATABASES['default']['NAME'])
        wafile = basename(DATABASES['default']['NAME'])
        wamd5 = get_md5_file(DATABASES['default']['NAME'])
        washa1 = get_sha1_file(DATABASES['default']['NAME'])
        waperm = "<b><font color=\"red\">YES (check file permissons)</font></b>" if access(DATABASES['default']['NAME'],W_OK) is True else "<b><font color=\"blue\">No</font></b>" 
    except:
        wusers = Messages.objects.using('msgstore').values('key_remote_jid').distinct().count()
        nwusers = 0
        wasize = 0
        wafile = "Not found!"
        wamd5 = "N/A"
        washa1 = "N/A"
        waperm = 'N/A'

    msgperm = "<b><font color=\"red\">YES (check file permissons)</font></b>" if access(DATABASES['msgstore']['NAME'],W_OK) is True else "<b><font color=\"blue\">No</font></b>"

    dic = {
            'whatsappusers': wusers,
            'nonwhatsappusers': nwusers,
            'activity': get_activity_data(None),
            'fromme': Messages.objects.using('msgstore').filter(key_from_me=1).count(),
            'tome': Messages.objects.using('msgstore').filter(key_from_me=0).count(),
            'latest': get_latest_peers(),
            'toppeers': get_top_peers(),
            'msgsize': getsize(DATABASES['msgstore']['NAME']),
            'msgfile': basename(DATABASES['msgstore']['NAME']),
            'msgperm': msgperm,
            'msgmd5': get_md5_file(DATABASES['msgstore']['NAME']),
            'msgsha1': get_sha1_file(DATABASES['msgstore']['NAME']),
            'wasize': wasize,
            'wafile': wafile,
            'wamd5': wamd5,
            'waperm': waperm,
            'washa1': washa1,
            }

    return render_to_response('whatsapp/index.html', dic, context_instance=RequestContext(request))
Exemplo n.º 5
0
def index(request):
    
    try:
        wusers = WaContacts.objects.filter(is_whatsapp_user = 1).count()
        nwusers = WaContacts.objects.filter(is_whatsapp_user = 0).count()
        wasize = getsize(DATABASES['default']['NAME'])
        wafile = basename(DATABASES['default']['NAME'])
        wamd5 = get_md5_file(DATABASES['default']['NAME'])
        washa1 = get_sha1_file(DATABASES['default']['NAME'])
    except:
        wusers = Messages.objects.using('msgstore').values('key_remote_jid').distinct().count()
        nwusers = 0
        wasize = 0
        wafile = "Not found!"
        wamd5 = "N/A"
        washa1 = "N/A"
    
    dic = {
            'whatsappusers': wusers,
            'nonwhatsappusers': nwusers,
            'activity': get_activity_data(None),
            'fromme': Messages.objects.using('msgstore').filter(key_from_me = 1).count(),
            'tome': Messages.objects.using('msgstore').filter(key_from_me = 0).count(),
            'latest': get_latest_peers(),
            'toppeers': get_top_peers(),
            'msgsize': getsize(DATABASES['msgstore']['NAME']),
            'msgfile': basename(DATABASES['msgstore']['NAME']),
            'msgmd5': get_md5_file(DATABASES['msgstore']['NAME']),
            'msgsha1': get_sha1_file(DATABASES['msgstore']['NAME']),
            'wasize': wasize,
            'wafile': wafile,
            'wamd5': wamd5,
            'washa1': washa1,
            }

    return render_to_response('whatsapp/index.html',dic,context_instance=RequestContext(request))
Exemplo n.º 6
0
if __name__ == '__main__':
    experiment_id = int(SystemRandom().random() * 100000)
    print(args, experiment_id)
    seed = args.seed
    torch.manual_seed(seed)
    np.random.seed(seed)
    torch.cuda.manual_seed(seed)
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

    if args.dataset == 'physionet':
        data_obj = utils.get_physionet_data(args, 'cpu', args.quantization)
    elif args.dataset == 'mimiciii':
        data_obj = utils.get_mimiciii_data(args)
    elif args.dataset == 'activity':
        data_obj = utils.get_activity_data(args, 'cpu')

    train_loader = data_obj["train_dataloader"]
    test_loader = data_obj["test_dataloader"]
    val_loader = data_obj["val_dataloader"]
    dim = data_obj["input_dim"]

    # model
    if args.enc == 'mtan_enc':
        rec = models.enc_mtan_classif(dim, torch.linspace(0, 1., 128),
                                      args.rec_hidden, args.embed_time,
                                      args.num_heads, args.learn_emb,
                                      args.freq).to(device)

    elif args.enc == 'mtan_enc_activity':
        rec = models.enc_mtan_classif_activity(dim, args.rec_hidden,
Exemplo n.º 7
0
parser.add_argument("--num-ref-points", type=int, default=128)
parser.add_argument("--classify-pertp", action="store_true")
args = parser.parse_args()

if __name__ == "__main__":
    experiment_id = int(SystemRandom().random() * 100000)
    print(args, experiment_id)
    seed = args.seed
    torch.manual_seed(seed)
    np.random.seed(seed)
    torch.cuda.manual_seed(seed)
    random.seed(seed)
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

    if args.dataset == "activity":
        data_obj = utils.get_activity_data(args, "cpu")

    train_loader = data_obj["train_dataloader"]
    test_loader = data_obj["test_dataloader"]
    val_loader = data_obj["val_dataloader"]
    dim = data_obj["input_dim"]

    if args.enc == "enc_rnn3":
        rec = models.enc_rnn3(
            dim,
            torch.linspace(0, 1.0, 50),
            args.latent_dim,
            args.rec_hidden,
            128,
            learn_emb=args.learn_emb,
        ).to(device)