コード例 #1
0
ファイル: mitfit_tasks.py プロジェクト: nmantri/openPDS
def leaderboardComputationTask():
    profiles = Profile.objects.all()
    #    profiles = []
    #    profiles.append(Profile.objects.get(uuid="341cc5cd-0f42-45f1-9f66-273ac3ed8b2e"))

    unsorted_dict = {}
    for profile in profiles:
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token)

        values = aggregateLeaderboardComputation(internalDataStore,
                                                 "activityStats",
                                                 leaderboardComputation, False)
        unsorted_dict[profile.uuid] = LeaderboardRanking({
            "average_activity_rate":
            values[0]["average_activity_rate"],
            "max_high_activity_rate":
            values[0]["max_high_activity_rate"],
            "min_low_activity_rate":
            values[0]["min_low_activity_rate"]
        })

    #sorted_dict = sorted(unsorted_dict.values(), key=attrgetter('average_activity_rate'))
    sorted_dict = sorted(
        unsorted_dict,
        key=lambda uuid: unsorted_dict[uuid].average_activity_rate,
        reverse=False)

    average_activity_rates_list = []
    for uuid in sorted_dict:
        average_activity_rates_list.append(
            unsorted_dict[uuid].get_average_activity_rate())

    for uuid in sorted_dict:
        profile = Profile.objects.get(uuid=uuid)
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token)

        percentileValue = calculatePercentile(
            average_activity_rates_list,
            unsorted_dict[uuid].get_average_activity_rate())

        user_activity_list = []
        user_activity_dict = {
            "average_activity_rate":
            unsorted_dict[uuid].get_average_activity_rate(),
            "max_high_activity_rate":
            unsorted_dict[uuid].get_max_high_activity_rate(),
            "min_low_activity_rate":
            unsorted_dict[uuid].get_min_low_activity_rate(),
            "rank": {
                "own": len(sorted_dict) - sorted_dict.index(uuid),
                "total": len(sorted_dict),
                "percentile": percentileValue
            }
        }
        user_activity_list.append(user_activity_dict)
        internalDataStore.saveAnswer("activityStats", user_activity_list)
コード例 #2
0
ファイル: mitfit_tasks.py プロジェクト: guyz/openPDS
def leaderboardComputationTask():
    profiles = Profile.objects.all()
#    profiles = []
#    profiles.append(Profile.objects.get(uuid="341cc5cd-0f42-45f1-9f66-273ac3ed8b2e"))

    unsorted_dict = {}
    for profile in profiles:
	token = socialhealth_tasks.getToken(profile, "app-uuid")
	internalDataStore = socialhealth_tasks.getInternalDataStore(profile, "Living Lab", "Social Health Tracker", token)
	
	values = aggregateLeaderboardComputation(internalDataStore, "activityStats", leaderboardComputation, False)
        unsorted_dict[profile.uuid] = LeaderboardRanking({ "average_activity_rate": values[0]["average_activity_rate"], "max_high_activity_rate": values[0]["max_high_activity_rate"], "min_low_activity_rate": values[0]["min_low_activity_rate"]})
	
    #sorted_dict = sorted(unsorted_dict.values(), key=attrgetter('average_activity_rate'))
    sorted_dict = sorted(unsorted_dict, key = lambda uuid: unsorted_dict[uuid].average_activity_rate, reverse=False)
 
    average_activity_rates_list = []
    for uuid in sorted_dict:
	average_activity_rates_list.append(unsorted_dict[uuid].get_average_activity_rate())
   
    for uuid in sorted_dict:
        profile = Profile.objects.get(uuid=uuid)
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(profile, "Living Lab", "Social Health Tracker", token)

	percentileValue = calculatePercentile(average_activity_rates_list, unsorted_dict[uuid].get_average_activity_rate())	

        user_activity_list = []
        user_activity_dict = { "average_activity_rate": unsorted_dict[uuid].get_average_activity_rate(), "max_high_activity_rate": unsorted_dict[uuid].get_max_high_activity_rate(), "min_low_activity_rate": unsorted_dict[uuid].get_min_low_activity_rate(), "rank": {"own": len(sorted_dict) - sorted_dict.index(uuid), "total": len(sorted_dict), "percentile": percentileValue} }
        user_activity_list.append(user_activity_dict)
        internalDataStore.saveAnswer("activityStats", user_activity_list)
コード例 #3
0
ファイル: mitfit_tasks.py プロジェクト: guyz/openPDS
def findActiveLocationsTask():
    profiles = Profile.objects.all()

    location_frequencies = {}
    for profile in profiles:
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(profile, "Living Lab", "Social Health Tracker", token)

        values = activeLocationsComputation(internalDataStore)
	print profile.uuid
	print values
	
	for value in values:
		location_value = tuple((round(value[0],4), round(value[1],4)))
		if location_value in location_frequencies:
			location_frequencies[location_value] = location_frequencies[location_value] + 1
		else:
			location_frequencies[location_value] = 1

    print location_frequencies

    location_frequencies_list = []
    for key  in location_frequencies:
	print key 
	location_value = { "lat": key[0], "lng": key[1], "count": location_frequencies[key]}	
	location_frequencies_list.append(location_value)

    print location_frequencies_list

    for profile in profiles:
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(profile, "Living Lab", "Social Health Tracker", token)
	
	internalDataStore.saveAnswer("activeLocations", location_frequencies_list)	
コード例 #4
0
def recentProbeDataScores():
    profiles = Profile.objects.all()
    for profile in profiles:
        startTime = socialhealth_tasks.getStartTime(6, True)
        currentTime = time.time()
        timeRanges = [
            (start, start + 3600)
            for start in range(int(startTime), int(currentTime), 3600)
        ]

        probeAnswerKeys = {
            'recentActivityProbeByHour': 'ActivityProbe',
            'recentSmsProbeByHour': 'SmsProbe',
            'recentCallLogProbeByHour': 'CallLogProbe',
            'recentBluetoothProbeByHour': 'BluetoothProbe',
            'recentWifiProbeByHour': 'WifiProbe',
            'recentSimpleLocationProbeByHour': 'LocationProbe',
            'recentRunningApplicationsProbeByHour': 'RunningApplicationsProbe',
            'recentHardwareInfoProbeByHour': 'HardwareInfoProbe',
            'recentAppUsageProbeByHour': 'AppUsageProbe'
        }

        #        print profile
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token)

        for probeAnswerKey, probe in probeAnswerKeys.iteritems():
            #            print probe
            probeLevels = aggregateForUser(probe, internalDataStore,
                                           probeAnswerKey, timeRanges,
                                           probeForTimeRange, False)
コード例 #5
0
def recentProbeDataScores():
    #    profile = Profile.objects.get(uuid = uuid)
    profiles = Profile.objects.all()
    for profile in profiles:
        startTime = socialhealth_tasks.getStartTime(6, True)
        currentTime = time.time()
        timeRanges = [(start, start + 3600) for start in range(int(startTime), int(currentTime), 3600)]

        probeAnswerKeys = {
            "recentActivityProbeByHour": "ActivityProbe",
            "recentSmsProbeByHour": "SmsProbe",
            "recentCallLogProbeByHour": "CallLogProbe",
            "recentBluetoothProbeByHour": "BluetoothProbe",
            "recentWifiProbeByHour": "WifiProbe",
            "recentSimpleLocationProbeByHour": "LocationProbe",
            "recentRunningApplicationsProbeByHour": "RunningApplicationsProbe",
            "recentHardwareInfoProbeByHour": "HardwareInfoProbe",
            "recentAppUsageProbeByHour": "AppUsageProbe",
        }

        print profile
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token
        )

        for probeAnswerKey, probe in probeAnswerKeys.iteritems():
            print probe
            probeLevels = aggregateForUser(
                probe, internalDataStore, probeAnswerKey, timeRanges, probeForTimeRange, False
            )
            print probeLevels
コード例 #6
0
ファイル: mitfit_tasks.py プロジェクト: nmantri/openPDS
def findActiveLocationsTask():
    profiles = Profile.objects.all()

    location_frequencies = {}
    for profile in profiles:
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token)

        values = activeLocationsComputation(internalDataStore)
        print profile.uuid
        print values

        for value in values:
            location_value = tuple((round(value[0], 4), round(value[1], 4)))
            if location_value in location_frequencies:
                location_frequencies[
                    location_value] = location_frequencies[location_value] + 1
            else:
                location_frequencies[location_value] = 1

    print location_frequencies

    location_frequencies_list = []
    for key in location_frequencies:
        print key
        location_value = {
            "lat": key[0],
            "lng": key[1],
            "count": location_frequencies[key]
        }
        location_frequencies_list.append(location_value)

    print location_frequencies_list

    for profile in profiles:
        token = socialhealth_tasks.getToken(profile, "app-uuid")
        internalDataStore = socialhealth_tasks.getInternalDataStore(
            profile, "Living Lab", "Social Health Tracker", token)

        internalDataStore.saveAnswer("activeLocations",
                                     location_frequencies_list)