Exemplo n.º 1
0
def process_number_people():
    data = request.json
    value = data['value']
    if isfile('calculations.json'):
        with open('calculations.json', 'r') as f:
            calculations=json.load(f)
    else:
        with open('calculations_base.json', 'r') as f:
           calculations=json.load(f)
    calculations['minPeople']['value'] = calculations['minPeople']['value'] + value
    if calculations['minPeople']['value'] < 0 :
        calculations['minPeople']['value'] = 0
    calculations['minPeople']['timestamp'] = gererate_timestamp()
    with open('calculations.json', 'w') as outfile:
        json.dump(calculations, outfile)
    return "Number of people correctly updated",200
Exemplo n.º 2
0
def process_number_people():
    data = request.json
    value = data["value"]
    if isfile("calculations.json"):
        with open("calculations.json", "r") as f:
            calculations = json.load(f)
    else:
        with open("calculations_base.json", "r") as f:
            calculations = json.load(f)
    calculations["minPeople"]["value"] = calculations["minPeople"]["value"] + value
    if calculations["minPeople"]["value"] < 0:
        calculations["minPeople"]["value"] = 0
    calculations["minPeople"]["timestamp"] = gererate_timestamp()
    with open("calculations.json", "w") as outfile:
        json.dump(calculations, outfile)
    return "Number of people correctly updated", 200
Exemplo n.º 3
0
def _communicasting_cron():
    app.logger.info("Communicasting's cron started")
    while True:
        #print "Communicasting cron sleeping for 3600 seconds"
        app.logger.info("Communicasting's cron sleeping for 3600 seconds")
        #sleep(3600)
        sleep(10)
        activeness = json.loads(isCalculationMade("activeness",2))
        socialization = json.loads(isCalculationMade("socialization",2))
        stamp = gererate_timestamp()
        today = datetime.fromtimestamp(stamp)
        previous_hour=today-timedelta(hours=1)
        #date = datetime.now()
        date = '%s-%s-%s'%(previous_hour.year,previous_hour.month,previous_hour.day)
        data = {}
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        data['date'] = date
        data['startTime'] = str(previous_hour.hour) + ':01'
        data['endTime'] = str(previous_hour.hour) + ':59'
        data['title'] = 'The activeness'
        data['description'] = 'The last hour\'s activeness is '+ str(activeness['value'])
        data['userId'] = UID
        data['topic'] = 'Activity'
        #print "Sending the activeness level to the Communicasting",data
        app.logger.info("Sending the activeness level to the Communicasting \n" + dict_to_string(data))
        #print "Respone of PUSH UI",requests.post(sms_url+'/message.sms', data=json.dumps(data),headers=headers, verify=False).json
        response_json = requests.post(sms_url+'/message.sms', data=json.dumps(data),headers=headers, verify=False).json()
        app.logger.info("Response of PUSH UI " + str(response_json))
        data = {}
        data['title'] = 'The socialization level'
        data['description'] = 'The last hours\'s socialization level is '+str(socialization['value'])
        data['userId'] = UID
        data['topic'] = 'Activity'
        data['startTime'] = str(previous_hour.hour) + ':01'
        data['endTime'] = str(previous_hour.hour) + ':59'
        data['date'] = date
        #print "Sending socialization level to the Communicasting",data
        app.logger.info("Sending the socialization level to the Communicasting \n" +  dict_to_string(data))
        #print "Response of PUSH UI",requests.post(sms_url+'/message.sms', data=json.dumps(data),headers=headers, verify=False).json
        response_json = requests.post(sms_url+'/message.sms', data=json.dumps(data),headers=headers, verify=False).json()
        app.logger.info("Response of PUSH UI " + str(response_json))
Exemplo n.º 4
0
def isCalculationMade(type,mode):
    if isfile('calculations.json'):
        with open('calculations.json', 'r') as f:
            calculations=json.load(f)
    else:
        with open('calculations_base.json', 'r') as f:
           calculations=json.load(f)
    data = calculations[type]
    date = datetime.fromtimestamp(data['timestamp'])
    stamp = gererate_timestamp()
    today = datetime.fromtimestamp(stamp)
    #today=datetime(2015,6,16,15,11,18)
    if date.day == today.day and date.month == today.month and date.year == today.year:
        if mode == 1:
            return json.dumps(data)
        elif  mode == 2 and date.hour == today.hour:
            return json.dumps(data)
        elif mode == 2:
            return makeCalculation(today,type,mode,calculations)
    else:
        return makeCalculation(today,type,mode,calculations)
Exemplo n.º 5
0
def _communicasting_cron():
    while True:
        print "Communicasting cron sleeping for 3600 seconds"
        sleep(10)
        activeness = json.loads(isCalculationMade("activeness", 2))
        socialization = json.loads(isCalculationMade("socialization", 2))
        stamp = gererate_timestamp()
        today = datetime.fromtimestamp(stamp)
        previous_hour = today - timedelta(hours=1)
        # date = datetime.now()
        date = "%s-%s-%s" % (previous_hour.year, previous_hour.month, previous_hour.day)
        data = {}
        headers = {"Content-type": "application/json", "Accept": "text/plain"}
        data["date"] = date
        data["startTime"] = str(previous_hour.hour) + ":01"
        data["endTime"] = str(previous_hour.hour) + ":59"
        data["title"] = "The activeness"
        data["description"] = "The last hour's activeness is " + str(activeness["value"])
        data["userId"] = UID
        data["topic"] = "Activity"
        print "Sending the activeness level to the Push UI", data
        print "Respone of PUSH UI", requests.post(
            "http://sonopa.c.smartsigns.nl/venuemaster-web-unified/sms/api/message.sms",
            data=json.dumps(data),
            headers=headers,
        ).json
        data = {}
        data["title"] = "The socialization level"
        data["description"] = "The last hours's socialization level is " + str(socialization["value"])
        data["userId"] = UID
        data["topic"] = "Activity"
        data["startTime"] = str(previous_hour.hour) + ":01"
        data["endTime"] = str(previous_hour.hour) + ":59"
        data["date"] = date
        print "Sending socialization level to the Push UI", data
        print "Response of PUSH UI", requests.post(
            "http://sonopa.c.smartsigns.nl/venuemaster-web-unified/sms/api/message.sms",
            data=json.dumps(data),
            headers=headers,
        ).json