Ejemplo n.º 1
0
    def GET(self):

        web.header('Content-Type', 'application/json')

        #get policy history (used in table display on a Profile page)
        policy_history = policies_model.get_policy_history(context.user_id())

        #get risks, costs for all months played by a user (used in graphs display on a Profile page)
        userid = context.user_id()
        scores = db.select('scores',
                           where='userid=$userid',
                           order="date ASC",
                           vars=locals())
        scores_result = []
        for row in scores:
            tmp = {}
            for key, value in row.iteritems():
                tmp[key] = str(value)
            scores_result.append(tmp)
        history = json.dumps({
            'policy_history': json.dumps(policy_history),
            'graph_data': json.dumps(scores_result)
        })

        if history:
            return history
Ejemplo n.º 2
0
    def GET(self):

        web.header('Content-Type', 'application/json')

        #get policy history (used in table display on a Profile page)
        policy_history = policies_model.get_policy_history(context.user_id())

        #get risks, costs for all months played by a user (used in graphs display on a Profile page)
        userid = context.user_id()
        scores = db.select('scores', where='userid=$userid', order="date ASC", vars=locals())
        scores_result = []
        for row in scores:
            tmp = {}
            for key, value in row.iteritems():
                tmp[key] = str(value)
            scores_result.append(tmp)
        history = json.dumps(
            {
            'policy_history': json.dumps(policy_history),
            'graph_data': json.dumps(scores_result)
            }
        )

        if history:
            return history
Ejemplo n.º 3
0
    def GET(self, id=0):
        """
        If given ID, returns dump of incident details.
        TODO: Should probably return also incident context (employee, location, ...) details
        """
        if id != 0:
            web.header('Content-Type', 'application/json')
            return json.dumps(model.get_incident(ident=id))

        prev_policies = policies_model.get_policy_history(context.user_id(),
                                                          latest=True)
        # Controllers (and the server as a whole) should not know about the way data is predicted.

        # Regardless how it works, the simulation should appear to the outside
        # as one model that takes a policy and returns an incident

        for policy in prev_policies:
            policy_context = {
                "employees": [policy['employee']],
                "locations": [policy['location']],
                "devices": [policy['device']]
            }
            related = sim_model().request(policy, policy_context)
            most_probable = model.get_most_probable(related)
        return most_probable['name']
Ejemplo n.º 4
0
    def GET(self, id=0):
        """
        If given ID, returns dump of incident details.
        TODO: Should probably return also incident context (employee, location, ...) details
        """
        if id != 0:
            web.header('Content-Type', 'application/json')
            return json.dumps(model.get_incident(ident=id))

        prev_policies = policies_model.get_policy_history(context.user_id(), latest=True)
        # Controllers (and the server as a whole) should not know about the way data is predicted.

        # Regardless how it works, the simulation should appear to the outside
        # as one model that takes a policy and returns an incident

        for policy in prev_policies:
            policy_context = {
                "employees": [policy['employee']],
                "locations": [policy['location']],
                "devices":[policy['device']]}
            related = sim_model().request(policy, policy_context)
            most_probable = model.get_most_probable(related)
        return most_probable['name']
Ejemplo n.º 5
0
 def GET(self):
     last_policy = policies_model.get_policy_history(context.user_id(), latest=True)
     # TODO here taking only the first one. should actually handle all 27 (3x3x3) of them
     last_policy = last_policy[0]
     print classifier_sklearn().predict_data(last_policy)[0]
     return classifier_sklearn().predict_data(last_policy)[0]
Ejemplo n.º 6
0
 def GET(self):
     policy_history = policies_model.get_policy_history(context.user_id())
     if policy_history:
         return json.dumps(policy_history)