Esempio n. 1
0
    def obj_create(self, bundle, request=None, **kwargs):
        #pdb.set_trace()
        requester = bundle.data["requester"]
        owner = request.GET["datastore_owner__uuid"]
        token = request.GET["bearer_token"]
        profile = Profile.objects.get(uuid=owner)
        meetup = None

        if "uuid" in bundle.data:
            ids = getInternalDataStore(profile, "Living Lab", "Meetup", token)
            meetup = ids.getMeetupRequest(bundle.data["uuid"])
        else:
            bundle.data["uuid"] = str(uuid.uuid4())

        if meetup is not None:
            # We're updating a pre-existing request instead of creating a new one...
            kwargs["pk"] = meetup["_id"]
            return self.obj_update(bundle, request, **kwargs)
        else:
            bundle.data["approved"] = bundle.data.get("approved", False)
            bundle.data["approvals"] = bundle.data.get("approvals", [])

        if requester == owner:
            # If we're the initiator, we need to notify the other participants...
            sendMeetupRequestToParticipants.apply_async(args=(bundle.data,
                                                              token))

        #bundle.data["approved"] = True  # Owner requesting it implies approva
        return super(MeetupRequestResource,
                     self).obj_create(bundle, request, **kwargs)
Esempio n. 2
0
    def obj_create(self, bundle, request=None, **kwargs):
        # pdb.set_trace()
        requester = bundle.data["requester"]
        owner = request.GET["datastore_owner__uuid"]
        token = request.GET["bearer_token"]
        profile = Profile.objects.get(uuid=owner)
        meetup = None

        if "uuid" in bundle.data:
            ids = getInternalDataStore(profile, "Living Lab", "Meetup", token)
            meetup = ids.getMeetupRequest(bundle.data["uuid"])
        else:
            bundle.data["uuid"] = str(uuid.uuid4())

        if meetup is not None:
            # We're updating a pre-existing request instead of creating a new one...
            kwargs["pk"] = meetup["_id"]
            return self.obj_update(bundle, request, **kwargs)
        else:
            bundle.data["approved"] = bundle.data.get("approved", False)
            bundle.data["approvals"] = bundle.data.get("approvals", [])

        if requester == owner:
            # If we're the initiator, we need to notify the other participants...
            sendMeetupRequestToParticipants.apply_async(args=(bundle.data, token))

        # bundle.data["approved"] = True  # Owner requesting it implies approva
        return super(MeetupRequestResource, self).obj_create(bundle, request, **kwargs)
Esempio n. 3
0
def update_approval_status(request):
    params = get_parameters(request, [
        "meetup_uuid", "participant", "bearer_token", "datastore_owner",
        "approved"
    ])
    if len(params) == 0:
        return HttpResponse("", status=401)

    token = params[2]
    owner_uuid = params[3]
    meetup_uuid = params[0]
    participant_uuid = params[1]
    approved = params[4]

    profile = Profile.objects.get(uuid=owner_uuid)

    ids = getInternalDataStore(profile, token)
    if approved:
        ids.addParticipantToApprovals(meetup_uuid, participant_uuid)
    # NOTE: what to do if approved is False? Remove them from approvals or from the participants also? What if the computation has already started?
    #else:
    #    ids.removeParticipantFromMeetupRequest(meetup_uuid, participant_uuid)
    meetup_request = ids.getMeetupRequest(meetup_uuid)
    if "approvals" in meetup_request and len(
            meetup_request["approvals"]) == len(
                meetup_request["participants"]):
        initiateMeetupScheduling.apply_async(args=(owner_uuid, meetup_uuid,
                                                   token))
    #scheduleMeetup.apply_async(args=(owner_uuid, meetup_uuid, token))
    return HttpResponse("")
Esempio n. 4
0
def initiateMeetupScheduling(owner_uuid, meetup_uuid, token):
    owner = Profile.objects.get(uuid=owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup",
                                             token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)

    owner_places = internalDataStore.getAnswerList("HourlyPlaces")[0]["value"]

    answer = []

    for place in [p for p in owner_places if p["key"] not in ["work", "home"]]:
        answer.append({
            "key": place["key"],
            "total_distance": 0,
            "total_variance": 0,
            "center": (0, 0)
        })

    #internalDataStore.saveAnswer("Meetup%s"%meetup_uuid, answer)

    next_uuid = meetup_request["participants"][0]

    print "%s initiating meetup scheduling for %s" % (owner_uuid, meetup_uuid)
    next_contribution_url = settings.DEFAULT_PDS_URL + "/meetup/help_schedule?meetup_uuid=%s&bearer_token=%s&datastore_owner__uuid=%s" % (
        meetup_uuid, token, next_uuid)
    requests.post(next_contribution_url,
                  data=json.dumps(answer),
                  headers={"content-type": "application/json"})
Esempio n. 5
0
def helpScheduleMeetup(owner_uuid, meetup_uuid, running_totals, token):
    print "%s contributing to meetup %s" % (owner_uuid, meetup_uuid)
    owner = Profile.objects.get(uuid=owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup",
                                             token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)
    requester_uuid = meetup_request["requester"]

    participant_uuids = meetup_request["participants"]
    my_index = len(
        participant_uuids
    ) if owner_uuid == requester_uuid else participant_uuids.index(owner_uuid)

    owner_places = internalDataStore.getAnswerList("HourlyPlaces")[0]["value"]
    answer = []
    for scores in running_totals:
        key = scores["key"]
        place = next((p for p in owner_places if p["key"] == key), None)
        total_distance = scores["total_distance"]
        total_variance = scores["total_variance"]
        center = scores["center"]
        if place is not None:
            new_distance, new_variance, new_center = updateMeetupScore(
                total_distance, total_variance, center, my_index, place)
        else:
            new_distance = total_distance + 99999999
            new_variance = total_variance + 99999999
            new_center = center
        answer.append({
            "key": key,
            "total_distance": new_distance,
            "total_variance": new_variance,
            "center": new_center
        })

    #internalDataStore.saveAnswer("Meetup%s"%meetup_uuid, answer)
    if my_index < len(participant_uuids) - 1:
        next_uuid = participant_uuids[my_index + 1]
    else:
        next_uuid = requester_uuid

    if owner_uuid == requester_uuid:
        chooseMeetupAndPushResult(meetup_request, answer, token)
    else:
        next_contribution_url = settings.DEFAULT_PDS_URL + "/meetup/help_schedule?meetup_uuid=%s&bearer_token=%s&datastore_owner__uuid=%s" % (
            meetup_uuid, token, next_uuid)
        requests.post(next_contribution_url,
                      data=json.dumps(answer),
                      headers={"content-type": "application/json"})
Esempio n. 6
0
def scheduleMeetup(owner_uuid="280e418a-8032-4de3-b62a-ad173fea4811", meetup_uuid="", token="b3dbac8916"):
     
    participant_uuids=["5241576e-43da-4b08-8a71-b477f931e021", "72d9d8e3-3a57-4508-9515-2b881afc0d8e"]
    participant_places = {}
    owner = Profile.objects.get(uuid = owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup", token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)
    if meetup_request is None or "approved" not in meetup_request or not meetup_request["approved"]:
        return 
    owner_places = internalDataStore.getAnswerList("RecentPlaces")[0]["value"]

    for uuid in participant_uuids:
        url = settings.DEFAULT_PDS_URL+"/api/personal_data/answerlist/?key=RecentPlaces&datastore_owner__uuid=%s&bearer_token=%s"%(uuid, token)
        headers = { "content-type": "application/json" }
        requester_places = requests.get(url, headers = headers)
        print "Meetup between %s and %s"%(owner_uuid, uuid)
        if requester_places.status_code == requests.codes.ok:
            print requester_places.json()
            participant_places[uuid] = requester_places.json()["objects"][0]["value"]

    min_score = 9999999999 #proxy for int_max or whatever Python calls it
    min_score_key = None
    meeting_point = None
    participant_locations = []
    for place in [p for p in owner_places if p["key"] not in ["work", "home"]]:
        #print participant_places
        places_for_key = [p for uid in participant_uuids for p in participant_places[uid] if p["key"] == place["key"]]
        places_for_key.append(place)        
        score_for_key, point_for_key = scoreMeetup(places_for_key)  
        if score_for_key < min_score:
            print "%s < %s" % (score_for_key, min_score)
            min_score = score_for_key
            min_score_key = place["key"]
            meeting_point = point_for_key
            participant_locations = [(p["bounds"][0], p["bounds"][1]) for p in places_for_key]

    print "Best Time: %s" % min_score_key
    print "Meeting point: %s,%s" % meeting_point
    print participant_locations
    answer = internalDataStore.getAnswerList("Meetups")
    answer = answer[0]["value"] if answer is not None and answer.count() > 0 else []
    answer = [v for v in answer if "description" in v and v["description"] != description]
    answer.append({"description": description, "participants": participant_uuids, "hour": min_score_key, "place": meeting_point})
    internalDataStore.saveAnswer("Meetups", answer)
Esempio n. 7
0
def initiateMeetupScheduling(owner_uuid, meetup_uuid, token):
    owner = Profile.objects.get(uuid = owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup", token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)

    owner_places = internalDataStore.getAnswerList("HourlyPlaces")[0]["value"]

    answer = []
    
    for place in [p for p in owner_places if p["key"] not in ["work", "home"]]:
        answer.append({"key": place["key"], "total_distance": 0, "total_variance": 0, "center": (0,0) })

    #internalDataStore.saveAnswer("Meetup%s"%meetup_uuid, answer)

    next_uuid = meetup_request["participants"][0]
    
    print "%s initiating meetup scheduling for %s"%(owner_uuid, meetup_uuid)
    next_contribution_url = settings.DEFAULT_PDS_URL+"/meetup/help_schedule?meetup_uuid=%s&bearer_token=%s&datastore_owner__uuid=%s"%(meetup_uuid, token, next_uuid)
    requests.post(next_contribution_url, data=json.dumps(answer), headers={"content-type":"application/json"})
Esempio n. 8
0
def helpScheduleMeetup(owner_uuid, meetup_uuid, running_totals, token):
    print "%s contributing to meetup %s"%(owner_uuid, meetup_uuid)
    owner = Profile.objects.get(uuid = owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup", token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)
    requester_uuid = meetup_request["requester"]

    participant_uuids = meetup_request["participants"]
    my_index = len(participant_uuids) if owner_uuid == requester_uuid else participant_uuids.index(owner_uuid)
  
    owner_places = internalDataStore.getAnswerList("HourlyPlaces")[0]["value"]
    answer = []
    for scores in running_totals:
        key = scores["key"]
        place = next((p for p in owner_places if p["key"] == key), None)
        total_distance = scores["total_distance"]
        total_variance = scores["total_variance"]
        center = scores["center"]
        if place is not None:
            new_distance, new_variance, new_center = updateMeetupScore(total_distance, total_variance, center, my_index, place)
        else:
            new_distance = total_distance + 99999999
            new_variance = total_variance + 99999999
            new_center = center
        answer.append({"key": key, "total_distance": new_distance, "total_variance": new_variance, "center": new_center})

    #internalDataStore.saveAnswer("Meetup%s"%meetup_uuid, answer)
    if my_index < len(participant_uuids) - 1: 
        next_uuid = participant_uuids[my_index + 1]
    else:
        next_uuid = requester_uuid
    
    if owner_uuid == requester_uuid:
        chooseMeetupAndPushResult(meetup_request, answer, token)
    else:
        next_contribution_url = settings.DEFAULT_PDS_URL+"/meetup/help_schedule?meetup_uuid=%s&bearer_token=%s&datastore_owner__uuid=%s"%(meetup_uuid, token, next_uuid)
        requests.post(next_contribution_url,data=json.dumps(answer),headers={"content-type":"application/json"})
Esempio n. 9
0
def update_approval_status(request):
    params = get_parameters(request, ["meetup_uuid", "participant", "bearer_token", "datastore_owner", "approved"])
    if len(params) == 0:
        return HttpResponse("", status = 401)
    
    token = params[2]
    owner_uuid = params[3]
    meetup_uuid = params[0]
    participant_uuid = params[1]
    approved = params[4]

    profile = Profile.objects.get(uuid = owner_uuid)

    ids = getInternalDataStore(profile, token)
    if approved:
        ids.addParticipantToApprovals(meetup_uuid, participant_uuid)
    # NOTE: what to do if approved is False? Remove them from approvals or from the participants also? What if the computation has already started?
    #else:
    #    ids.removeParticipantFromMeetupRequest(meetup_uuid, participant_uuid)
    meetup_request = ids.getMeetupRequest(meetup_uuid)
    if "approvals" in meetup_request and len(meetup_request["approvals"]) == len(meetup_request["participants"]):
        initiateMeetupScheduling.apply_async(args=(owner_uuid, meetup_uuid, token))
    #scheduleMeetup.apply_async(args=(owner_uuid, meetup_uuid, token))
    return HttpResponse("")
Esempio n. 10
0
def scheduleMeetup(owner_uuid="280e418a-8032-4de3-b62a-ad173fea4811",
                   meetup_uuid="",
                   token="b3dbac8916"):

    participant_uuids = [
        "5241576e-43da-4b08-8a71-b477f931e021",
        "72d9d8e3-3a57-4508-9515-2b881afc0d8e"
    ]
    participant_places = {}
    owner = Profile.objects.get(uuid=owner_uuid)
    internalDataStore = getInternalDataStore(owner, "Living Lab", "Meetup",
                                             token)
    meetup_request = internalDataStore.getMeetupRequest(meetup_uuid)
    if meetup_request is None or "approved" not in meetup_request or not meetup_request[
            "approved"]:
        return
    owner_places = internalDataStore.getAnswerList("RecentPlaces")[0]["value"]

    for uuid in participant_uuids:
        url = settings.DEFAULT_PDS_URL + "/api/personal_data/answerlist/?key=RecentPlaces&datastore_owner__uuid=%s&bearer_token=%s" % (
            uuid, token)
        headers = {"content-type": "application/json"}
        requester_places = requests.get(url, headers=headers)
        print "Meetup between %s and %s" % (owner_uuid, uuid)
        if requester_places.status_code == requests.codes.ok:
            print requester_places.json()
            participant_places[uuid] = requester_places.json(
            )["objects"][0]["value"]

    min_score = 9999999999  #proxy for int_max or whatever Python calls it
    min_score_key = None
    meeting_point = None
    participant_locations = []
    for place in [p for p in owner_places if p["key"] not in ["work", "home"]]:
        #print participant_places
        places_for_key = [
            p for uid in participant_uuids for p in participant_places[uid]
            if p["key"] == place["key"]
        ]
        places_for_key.append(place)
        score_for_key, point_for_key = scoreMeetup(places_for_key)
        if score_for_key < min_score:
            print "%s < %s" % (score_for_key, min_score)
            min_score = score_for_key
            min_score_key = place["key"]
            meeting_point = point_for_key
            participant_locations = [(p["bounds"][0], p["bounds"][1])
                                     for p in places_for_key]

    print "Best Time: %s" % min_score_key
    print "Meeting point: %s,%s" % meeting_point
    print participant_locations
    answer = internalDataStore.getAnswerList("Meetups")
    answer = answer[0]["value"] if answer is not None and answer.count(
    ) > 0 else []
    answer = [
        v for v in answer
        if "description" in v and v["description"] != description
    ]
    answer.append({
        "description": description,
        "participants": participant_uuids,
        "hour": min_score_key,
        "place": meeting_point
    })
    internalDataStore.saveAnswer("Meetups", answer)