Exemplo n.º 1
0
def get_graph():
    response_builder = ResponseBuilder()
    nodes = response_builder.return_node_list(d_social_network_graph)
    edges = response_builder.return_edge_list(d_social_network_graph)

    response = dict()
    response["nodes"] = nodes
    response['edges'] = edges

    return jsonify(response)
Exemplo n.º 2
0
 def Switch(self, ps):
     #Objekt vom ResponseBuilder erstellen
     rb = ResponseBuilder()
     #Auf verwendete Methode testen und entsprechende ResponseBuilder-Methode aufrufen
     if ps.Method == "GET":
         response = rb.Getresponse(ps)
     elif ps.Method == "PUT":
         response = rb.Putresponse(ps)
     else:
         response = rb.Errorresponse(ps)
     #Vom ResponseBuilder erstellte Response an MainDatei weitergeben
     return response
Exemplo n.º 3
0
def handleTalk(intent, session):
    target = intent["slots"]["npc"]["value"]
    npcs = session["attributes"]["room"]["npcs"]
    npc_names = npcs.keys()

    if target in npc_names:
        title = npcs[target]["full_name"]
        reprompt_text = "What would you like to do?"
        output = npcs[target]["response"] + reprompt_text
    else:
        title = "Invalid Target"
        reprompt_text = "What would you like to do?"
        output = "I don't see a(ny) " + target + ". " + reprompt_text
    return ResponseBuilder.buildResponse(
        ResponseBuilder.buildSpeechletResponse(title, output, reprompt_text,
                                               False), session["attributes"])
Exemplo n.º 4
0
def handleInvestigate(intent, session):
    target = intent["slots"]["feature"]["value"]
    features = session["attributes"]["room"]["features"]
    feature_names = features.keys()

    if target in feature_names:
        title = features[target]["name"]
        reprompt_text = "What would you like to do?"
        output = features[target]["description"] + reprompt_text
    else:
        title = "Invalid Target"
        reprompt_text = "What would you like to do?"
        output = "I don't see a(ny) " + target + ". " + reprompt_text
    return ResponseBuilder.buildResponse(
        ResponseBuilder.buildSpeechletResponse(title, output, reprompt_text,
                                               False), session["attributes"])
Exemplo n.º 5
0
def handleIntent(intent, session):
    intent_name = intent["name"]

    if intent_name == "travel":
        return handleTravel(intent, session)
    elif intent_name == "investigate":
        return handleInvestigate(intent, session)
    elif intent_name == "talk":
        return handleTalk(intent, session)
    else:
        title = "Invalid Action"
        reprompt_text = "What would you like to do?"
        output = "You can't do that right now. " + reprompt_text
        return ResponseBuilder.buildResponse(
            ResponseBuilder.buildSpeechletResponse(title, output,
                                                   reprompt_text, False),
            session["attributes"])
Exemplo n.º 6
0
def get_school_communities():
    multi_school_community_graph = louvain.find_partition(d_social_network_graph, louvain.CPMVertexPartition,
                                       resolution_parameter=0.0005)
    for idx, community in enumerate(multi_school_community_graph):
        for node in community:
            v = d_social_network_graph.vs[node]
            v["groupId"] = idx

    response_builder = ResponseBuilder()
    nodes = response_builder.return_node_list(d_social_network_graph)
    edges = response_builder.return_edge_list(d_social_network_graph)

    response = dict()
    response["nodes"] = nodes
    response['edges'] = edges

    return jsonify(response)
Exemplo n.º 7
0
def handleTravel(intent, session):
    direction = intent["slots"]["direction"]["value"]
    connected = session["attributes"]["room"]["connected"]
    directions = connected.keys()

    if direction in directions:
        room_path = os.environ["LAMBDA_TASK_ROOT"] + "/Json/" + connected[
            direction] + ".json"
        room_data = open(room_path).read()
        session["attributes"]["room"] = json.loads(room_data)
    else:
        title = "Invalid Direction"
        reprompt_text = "What would you like to do?"
        output = "There is no way to go " + direction + ". " + reprompt_text
        return ResponseBuilder.buildResponse(
            ResponseBuilder.buildSpeechletResponse(title, output,
                                                   reprompt_text, False),
            session["attributes"])
Exemplo n.º 8
0
def strength():

    print('currency strength called')
    inpCur = request.json['inpCur']
    outCur = request.json['outCur']
    startDate = request.json['startDate']
    endDate = request.json['endDate']

    d1 = datetime.datetime(int(startDate[:4]), int(startDate[5:7]),
                           int(startDate[8:]))
    d2 = datetime.datetime(int(endDate[:4]), int(endDate[5:7]),
                           int(endDate[8:]))

    response = ResponseBuilder.getCurrencyStrenght(d1, d2, inpCur, outCur)
    return jsonify(response)
Exemplo n.º 9
0
def index():

    startDate = request.json['startDate']
    endDate = request.json['endDate']
    inpCur = request.json['inp']
    outCur = request.json['out']

    d1 = datetime.datetime(int(startDate[:4]), int(startDate[5:7]),
                           int(startDate[8:]))
    d2 = datetime.datetime(int(endDate[:4]), int(endDate[5:7]),
                           int(endDate[8:]))

    response = ResponseBuilder.getCurrencyPairData(d1, d2, inpCur, outCur)

    return jsonify(response)
Exemplo n.º 10
0
def percentagesum():

    startDate = request.json['startDate']
    endDate = request.json['endDate']
    inpCur = request.json['inpCur']
    outCur = request.json['outCur']

    d1 = datetime.datetime(int(startDate[:4]), int(startDate[5:7]),
                           int(startDate[8:]))
    d2 = datetime.datetime(int(endDate[:4]), int(endDate[5:7]),
                           int(endDate[8:]))

    print('d1 %s d2 %s  inpCur  %s outCur %s', d1, d2, inpCur, outCur)
    response = ResponseBuilder.getPercentageSum(d1, d2, inpCur, outCur)

    return jsonify(response)
Exemplo n.º 11
0
import cgi, meep_example_app, time, meepcookie, sys, socket, StringIO, urllib, ResponseBuilder

if __name__ == '__main__':
    meep_example_app.initialize()
    interface, port = sys.argv[1:3]
    port = int(port)

    print 'Binding', interface, port
    sock = socket.socket()
    sock.bind((interface, port))
    sock.listen(5)

    while 1:
        print 'Waiting for HTTP Request...'
        (client_sock, client_address) = sock.accept()
        print 'got connection', client_address
        ResponseBuilder.handle_connection(client_sock)
Exemplo n.º 12
0
# vrvi niz nizata i ja exekutira strategijata

import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import pandas as pd
import ResponseBuilder, datetime

d1 = datetime.datetime(2015, 6, 26)
d2 = datetime.datetime(2017, 7, 26)
d3 = datetime.datetime(2013, 7, 26)

# ResponseBuilder.getPercentageSum(d1, d2, 'EUR', ['AUD', 'EUR', 'USD'])

# simpleRates = ResponseBuilder.getCurrencyPairData(d1, d2 , 'EUR', ['AUD', 'USD'])
currencyLaderRates = ResponseBuilder.getPercentageSum(d3, d2, 'EUR',
                                                      ['AUD', 'EUR', 'USD'])

# showcase
# df = pd.DataFrame(simpleRates['datasets'][0])
# print(df.head())
# df['avg10'] = df['rates'].rolling(window=10, min_periods=1 , center=False).mean()
# df['avg20'] = df['rates'].rolling(window=20, min_periods=1 , center=False).mean()
# print(df)

# x = [dt.datetime.strptime(d,'%Y-%m-%d').date() for d in simpleRates['labels']]
# plt.plot(x, simpleRates['datasets'][0]['rates'], color='g')
# plt.plot(x, df['avg10'], color='b')
# plt.plot(x, df['avg20'], color='r')
# print(df)
# plt.show()
Exemplo n.º 13
0
import cgi, meep_example_app, time, meepcookie, sys, socket, StringIO, urllib, ResponseBuilder



if __name__ == '__main__':
    meep_example_app.initialize()
    interface, port = sys.argv[1:3]
    port = int(port)

    print 'Binding', interface, port
    sock = socket.socket()
    sock.bind( (interface, port) )
    sock.listen(5)

    while 1:
        print 'Waiting for HTTP Request...'
        (client_sock, client_address) = sock.accept()
        print 'got connection', client_address
        ResponseBuilder.handle_connection(client_sock)
Exemplo n.º 14
0
def get_interest_based_communities():

    target_school = request.args.get('school')
    interests = request.args.get('interests').split(',')

    # Level 1 - School Community Detection
    multi_school_community_graph = louvain.find_partition(d_social_network_graph, louvain.CPMVertexPartition,
                                                        resolution_parameter=0.0005)
    school_community_id_map = {}
    for community_id,community in enumerate(multi_school_community_graph):
        min_check = len(community)*0.1
        if min_check >= 1:
            for i,node in enumerate(community):
                school_name = d_social_network_graph.vs[node]['school']
                if school_name in school_community_id_map:
                    school_community_id_map[school_name] += ","+str(community_id)
                else:
                    school_community_id_map[school_name] = str(community_id)
                i += 1
                if i > min_check:
                    break

    for school, community_id in school_community_id_map.iteritems():
        community_ids = community_id.split(",")
        school_community_id_map[school] = max(set(community_ids), key=community_ids.count)

    target_community_id = school_community_id_map.get(target_school)
    school_nodes = multi_school_community_graph[int(target_community_id)]

    # Level 2 Interest-based Community Detection
    school_community_graph = Graph()
    school_community_graph.to_directed()

    interest_based_community_graph = Graph()
    interest_based_community_graph.to_directed()

    updated_school_nodes = []

    for node in school_nodes:
        school_community_graph.add_vertex(d_social_network_graph.vs[node].index)
        updated_school_nodes.append(d_social_network_graph.vs[node])

    updated_school_node_ids=[]

    for i,v in enumerate(school_community_graph.vs):
        v["id"] = updated_school_nodes[i]["id"]
        v["label"] = updated_school_nodes[i]["label"]
        v["groupId"] = -1
        v['interestedNode']=False
        v['influentialNode']=False
        v["interest"] = updated_school_nodes[i]["interest"]
        updated_school_node_ids.append(updated_school_nodes[i]["id"])

    for e in d_social_network_graph.es:
        src = e.source
        dest = e.target
        if d_social_network_graph.vs[src]['id'] in updated_school_node_ids \
                and d_social_network_graph.vs[dest]['id'] in updated_school_node_ids:

            id_src = d_social_network_graph.vs[src]['id']
            id_dest = d_social_network_graph.vs[dest]['id']
            sg_src = school_community_graph.vs.find(id=id_src).index
            sg_dest = school_community_graph.vs.find(id=id_dest).index
            school_community_graph.add_edge(sg_src, sg_dest)

    interested_nodes = []

    for v in school_community_graph.vs:
        is_interested = False
        for interest in interests:
            if interest in v["interest"]:
                is_interested = True
            else:
                is_interested = False
                break
        if is_interested:
            v["interestedNode"] = True
            interested_nodes.append(v)


    # Compute shortest paths among sub-community nodes usinf Dijkstra's shortest path algorithm
    influenceFactorAdjGrid = d_social_network_graph.shortest_paths_dijkstra(interested_nodes, interested_nodes, None, OUT)
    interest_based_community_graph = Graph.Weighted_Adjacency(influenceFactorAdjGrid, ADJ_DIRECTED, "weight", False)
    interest_based_community_graph.simplify(combine_edges='sum')

    i = 0
    for v in interest_based_community_graph.vs:
        node = interested_nodes[i]
        v["id"] = node["id"]
        i += 1

    influentials_object = get_influential_node(interest_based_community_graph, school_community_graph)
    if len(influentials_object) > 0:
        for node_id in influentials_object[len(influentials_object)-1][2]:
            node_id["influentialNode"] = True

    response_builder = ResponseBuilder()
    nodes = response_builder.return_node_list(school_community_graph)
    edges = response_builder.return_edge_list(school_community_graph)

    # Json object for coverage graph
    nodes_coverage = []
    for item in influentials_object:
        temp_json = dict()
        temp_json["no_of_influencers"] = item[0]
        temp_json["coverage"] = item[1]
        temp_json["node_info"] = []
        for node in item[2]:
            curr_node = dict()
            curr_node["id"] = node["id"]
            curr_node["interest"] = node["interest"]
            curr_node["influentialNode"] = node["influentialNode"]
            curr_node["groupId"] = node["groupId"]
            curr_node["influence"] = node["influence"]
            curr_node["interestedNode"] = node["interestedNode"]
            curr_node["name"] = node["name"]
            temp_json["node_info"].append(curr_node)
        nodes_coverage.append(temp_json)

    response = dict()
    response["nodes"] = nodes
    response['edges'] = edges
    response['coverageObject'] = nodes_coverage

    return jsonify(response)