Get uniquevisitors per month from database.



  • I just wonder is it possible to get uniquevisitors per month from database something like analytics:pageviews:month.

    Right now i tried:

    >>> import pymongo
    >>> import urllib.parse
    >>> username = urllib.parse.quote_plus('nodebb')
    >>> password = urllib.parse.quote_plus('password')
    >>> database = 'nodebb'
    >>> client = pymongo.MongoClient('mongodb://{0}:{1}@localhost:1035/{2}'.format(username, password, database))
    >>> db = client['nodebb']
    >>> x = db.objects.find( {"_key":"analytics:uniquevisitors"} )
    [{'_id': ObjectId('5df09a9e55282ba145584758'), '_key': 'analytics:uniquevisitors', 'value': '1576047600000', 'score': 1}, 
    {'_id': ObjectId('5def922055282ba14556cd62'), '_key': 'analytics:uniquevisitors', 'value': '1575979200000', 'score': 1},
    {'_id': ObjectId('5def76e655282ba1455600fb'), '_key': 'analytics:uniquevisitors', 'value': '1575972000000', 'score': 1}, 
    {'_id': ObjectId('5def5cec55282ba14555556c'), '_key': 'analytics:uniquevisitors', 'value': '1575964800000', 'score': 1}, 
    {'_id': ObjectId('5def46f855282ba14554d247'), '_key': 'analytics:uniquevisitors', 'value': '1575961200000', 'score': 1}, 
    {'_id': ObjectId('5def3bc255282ba1455499b0'), '_key': 'analytics:uniquevisitors', 'value': '1575957600000', 'score': 1}, 
    {'_id': ObjectId('5dede3b21bf4964726f25229'), '_key': 'analytics:uniquevisitors', 'value': '1575871200000', 'score': 1}, 
    {'_id': ObjectId('5dead6403d0bdde682e68827'), '_key': 'analytics:uniquevisitors', 'value': '1575669600000', 'score': 1}, 
    {'_id': ObjectId('5deacab009d45de8c62faaa0'), '_key': 'analytics:uniquevisitors', 'value': '1575666000000', 'score': 2}, 
    {'_id': ObjectId('5de6e706453021d4cc7aeee4'), '_key': 'analytics:uniquevisitors', 'value': '1575410400000', 'score': 1}, 
    {'_id': ObjectId('5de6ced8453021d4cc7a7515'), '_key': 'analytics:uniquevisitors', 'value': '1575406800000', 'score': 1}, 
    {'_id': ObjectId('5de59c2a721e4123b1946894'), '_key': 'analytics:uniquevisitors', 'value': '1575327600000', 'score': 1}]
    

    But I don't know how to process this data further to get unique visitors per month.

    Is value a timestamp? So i would check witch timestamp match previous month.



  • @MoJo said in Get uniquevisitors per month from database.:

    Is value a timestamp? So i would check witch timestamp match previous month.

    Yes and then sum the scores.



  • Correct me if I'm wrong. I'm really not sure if what you're trying to do. Are you trying to create a unique visitor graph or are you simply trying to display the unique Visitors for that current month? However, I think MongoDB timestamp is much similar to javascript time stamp. MongoDB has some built-in command to convert it however you can just as easily do this with javaScript.

    var objectIdFromDate = function (date) {
    	return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000";
    };
    
    var dateFromObjectId = function (objectId) {
    	return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
    };
    	
    

Log in to reply
 

Suggested Topics

| |