예제 #1
0
    def get_modality(self, modality_id: int):
        """
        Send request to graph api to get given modality

        Args:
        modality_id (int): Id of modality

        Returns:
            Result of request as modality object
        """
        get_response = self.graph_api_service.get_node(modality_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=modality_id, errors=get_response["errors"])
        if get_response["labels"][0] != "Modality":
            return NotFoundByIdModel(id=modality_id, errors="Node not found.")

        modality = {'id': get_response['id'], 'relations': [], 'reversed_relations': []}
        for property in get_response["properties"]:
            modality[property["key"]] = property["value"]

        relations_response = self.graph_api_service.get_node_relationships(modality_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == modality_id:
                modality['relations'].append(RelationInformation(second_node_id=relation["end_node"],
                                                                 name=relation["name"], relation_id=relation["id"]))
            else:
                modality['reversed_relations'].append(RelationInformation(second_node_id=relation["start_node"],
                                                                          name=relation["name"],
                                                                          relation_id=relation["id"]))

        return ModalityOut(**modality)
예제 #2
0
    def get_arrangement(self, arrangement_id: int):
        """
        Send request to graph api to get given arrangement

        Args:
            arrangement_id (int): Id of arrangement

        Returns:
            Result of request as arrangement object
        """
        get_response = self.graph_api_service.get_node(arrangement_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=arrangement_id, errors=get_response["errors"])
        if get_response["labels"][0] != "Arrangement":
            return NotFoundByIdModel(id=arrangement_id, errors="Node not found.")

        arrangement = {'id': get_response['id'], 'relations': [], 'reversed_relations': []}
        for property in get_response["properties"]:
            arrangement[property["key"]] = property["value"]

        relations_response = self.graph_api_service.get_node_relationships(arrangement_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == arrangement_id:
                arrangement['relations'].append(RelationInformation(second_node_id=relation["end_node"],
                                                                    name=relation["name"], relation_id=relation["id"]))
            else:
                arrangement['reversed_relations'].append(RelationInformation(second_node_id=relation["start_node"],
                                                                             name=relation["name"],
                                                                             relation_id=relation["id"]))

        return ArrangementOut(**arrangement)
예제 #3
0
    def get_participant_state(self, participant_state_id: int):
        """
        Send request to graph api to get given participant state

        Args:
            participant_state_id (int): Id of participant state

        Returns:
            Result of request as participant state object
        """
        get_response = self.graph_api_service.get_node(participant_state_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=participant_state_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Participant State":
            return NotFoundByIdModel(id=participant_state_id,
                                     errors="Node not found.")

        participant_state = {
            'id': get_response['id'],
            'additional_properties': [],
            'relations': [],
            'reversed_relations': []
        }
        for property in get_response["properties"]:
            if property["key"] == "age":
                participant_state[property["key"]] = property["value"]
            else:
                participant_state['additional_properties'].append({
                    'key':
                    property['key'],
                    'value':
                    property['value']
                })

        relations_response = self.graph_api_service.get_node_relationships(
            participant_state_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == participant_state_id:
                participant_state['relations'].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                participant_state['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return ParticipantStateOut(**participant_state)
    def get_registered_data(self, registered_data_id: int):
        """
        Send request to graph api to get given registered data

        Args:
        registered_data_id (int): Id of registered data

        Returns:
            Result of request as registered data object
        """
        get_response = self.graph_api_service.get_node(registered_data_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=registered_data_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Registered Data":
            return NotFoundByIdModel(id=registered_data_id,
                                     errors="Node not found.")

        registered_data = {
            'id': get_response['id'],
            'additional_properties': [],
            'relations': [],
            'reversed_relations': []
        }
        for property in get_response["properties"]:
            if property["key"] == "source":
                registered_data[property["key"]] = property["value"]
            else:
                registered_data['additional_properties'].append({
                    'key':
                    property['key'],
                    'value':
                    property['value']
                })

        relations_response = self.graph_api_service.get_node_relationships(
            registered_data_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == registered_data_id:
                registered_data['relations'].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                registered_data['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return RegisteredDataOut(**registered_data)
예제 #5
0
    def update_personality_panas(self, personality_id: int,
                                 personality: PersonalityPanasIn):
        """
        Send request to graph api to update given personality panas model

        Args:
            personality_id (int): Id of personality
            personality (PersonalityPanasIn): Properties to update

        Returns:
            Result of request as personality object
        """
        if not 0 <= personality.negative_affect <= 1 or not 0 <= personality.positive_affect <= 1:
            return PersonalityPanasOut(**personality.dict(),
                                       errors="Value not between 0 and 1")

        get_response = self.get_personality(personality_id)
        if type(get_response) is NotFoundByIdModel:
            return get_response
        if type(get_response) is PersonalityBigFiveOut:
            return NotFoundByIdModel(id=personality_id,
                                     errors="Node not found.")

        self.graph_api_service.create_properties(personality_id, personality)

        personality_response = get_response.dict()
        personality_response.update(personality)
        return PersonalityPanasOut(**personality_response)
예제 #6
0
    def update_appearance_occlusion(self, appearance_id: int,
                                    appearance: AppearanceOcclusionIn):
        """
        Send request to graph api to update given appearance occlusion model

        Args:
            appearance_id (int): Id of appearance
            appearance (AppearanceOcclusionIn): Properties to update

        Returns:
            Result of request as appearance object
        """
        get_response = self.get_appearance(appearance_id)

        if type(get_response) is NotFoundByIdModel:
            return get_response
        if type(get_response) is AppearanceSomatotypeOut:
            return NotFoundByIdModel(id=appearance_id,
                                     errors="Node not found.")

        self.graph_api_service.create_properties(appearance_id, appearance)

        appearance_response = get_response.dict()
        appearance_response.update(appearance)
        return AppearanceOcclusionOut(**appearance_response)
예제 #7
0
    def update_appearance_somatotype(self, appearance_id: int,
                                     appearance: AppearanceSomatotypeIn):
        """
        Send request to graph api to update given appearance somatotype model

        Args:
            appearance_id (int): Id of appearance
            appearance (AppearanceSomatotypeIn): Properties to update

        Returns:
            Result of request as appearance object
        """
        if not 1 <= appearance.ectomorph <= 7 or not 1 <= appearance.endomorph <= 7 \
                or not 1 <= appearance.mesomorph <= 7:

            return AppearanceSomatotypeOut(
                **appearance.dict(), errors="Scale range not between 1 and 7")

        get_response = self.get_appearance(appearance_id)
        if type(get_response) is NotFoundByIdModel:
            return get_response
        if type(get_response) is AppearanceOcclusionOut:
            return NotFoundByIdModel(id=appearance_id,
                                     errors="Node not found.")

        self.graph_api_service.create_properties(appearance_id, appearance)

        appearance_response = get_response.dict()
        appearance_response.update(appearance)
        return AppearanceSomatotypeOut(**appearance_response)
예제 #8
0
    def update_personality_big_five(self, personality_id: int,
                                    personality: PersonalityBigFiveIn):
        """
        Send request to graph api to update given personality big five model

        Args:
            personality_id (int): Id of personality
            personality (PersonalityBigFiveIn): Properties to update

        Returns:
            Result of request as personality object
        """
        if not 0 <= personality.agreeableness <= 1 or not 0 <= personality.conscientiousness <= 1 or \
           not 0 <= personality.extroversion <= 1 or not 0 <= personality.neuroticism <= 1 or \
           not 0 <= personality.openess <= 1:
            return PersonalityBigFiveOut(**personality.dict(),
                                         errors="Value not between 0 and 1")

        get_response = self.get_personality(personality_id)
        if type(get_response) is NotFoundByIdModel:
            return get_response
        if type(get_response) is PersonalityPanasOut:
            return NotFoundByIdModel(id=personality_id,
                                     errors="Node not found.")

        self.graph_api_service.create_properties(personality_id, personality)
        personality_response = get_response.dict()
        personality_response.update(personality)
        return PersonalityBigFiveOut(**personality_response)
예제 #9
0
    def get_appearance(self, appearance_id: int):
        """
        Send request to graph api to get given appearance

        Args:
            appearance_id (int): Id of appearance

        Returns:
            Result of request as appearance object
        """
        get_response = self.graph_api_service.get_node(appearance_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=appearance_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Appearance":
            return NotFoundByIdModel(id=appearance_id,
                                     errors="Node not found.")

        appearance = {
            'id': appearance_id,
            'relations': [],
            'reversed_relations': []
        }
        appearance.update({
            property["key"]: property["value"]
            for property in get_response["properties"]
        })

        relations_response = self.graph_api_service.get_node_relationships(
            appearance_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == appearance_id:
                appearance["relations"].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                appearance["reversed_relations"].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return AppearanceOcclusionOut(**appearance) if "glasses" in appearance.keys() \
            else AppearanceSomatotypeOut(**appearance)
예제 #10
0
    def get_personality(self, personality_id: int):
        """
        Send request to graph api to get given personality

        Args:
            personality_id (int): Id of personality

        Returns:
            Result of request as personality object
        """
        get_response = self.graph_api_service.get_node(personality_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=personality_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Personality":
            return NotFoundByIdModel(id=personality_id,
                                     errors="Node not found.")

        personality = {
            'id': personality_id,
            'relations': [],
            'reversed_relations': []
        }
        personality.update({
            property["key"]: property["value"]
            for property in get_response["properties"]
        })

        relations_response = self.graph_api_service.get_node_relationships(
            personality_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == personality_id:
                personality["relations"].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                personality["reversed_relations"].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return PersonalityPanasOut(**personality) if "negative_affect" in personality.keys() \
            else PersonalityBigFiveOut(**personality)
예제 #11
0
    def get_registered_channel(self, registered_channel_id: int):
        """
        Send request to graph api to get given registered channel

        Args:
            registered_channel_id (int): Id of registered channel

        Returns:
            Result of request as registered channel object
        """
        get_response = self.graph_api_service.get_node(registered_channel_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=registered_channel_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Registered Channel":
            return NotFoundByIdModel(id=registered_channel_id,
                                     errors="Node not found.")

        registered_channel = {
            'id': get_response['id'],
            'relations': [],
            'reversed_relations': []
        }
        for property in get_response["properties"]:
            if property["key"] == "age":
                registered_channel[property["key"]] = property["value"]

        relations_response = self.graph_api_service.get_node_relationships(
            registered_channel_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == registered_channel_id:
                registered_channel['relations'].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                registered_channel['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return RegisteredChannelOut(**registered_channel)
예제 #12
0
    def get_measure(self, measure_id: int):
        """
        Send request to graph api to get given measure

        Args:
            measure_id (int): Id of measure

        Returns:
            Result of request as measure object
        """
        get_response = self.graph_api_service.get_node(measure_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=measure_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Measure":
            return NotFoundByIdModel(id=measure_id, errors="Node not found.")

        measure = {
            'id': get_response['id'],
            'relations': [],
            'reversed_relations': []
        }
        for property in get_response["properties"]:
            if property["key"] in ["datatype", "range", "unit"]:
                measure[property["key"]] = property["value"]

        relations_response = self.graph_api_service.get_node_relationships(
            measure_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == measure_id:
                measure['relations'].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                measure['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return MeasureOut(**measure)
예제 #13
0
    def get_observable_information(self, observable_information_id: int):
        """
        Send request to graph api to get given observable information
        Args:
            observable_information_id (int): Id of observable information
        Returns:
            Result of request as observable information object
        """
        get_response = self.graph_api_service.get_node(
            observable_information_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=observable_information_id,
                                     errors=get_response["errors"])
        if get_response["labels"][0] != "Observable Information":
            return NotFoundByIdModel(id=observable_information_id,
                                     errors="Node not found.")

        observable_information = {
            'id': get_response['id'],
            'relations': [],
            'reversed_relations': []
        }

        relations_response = self.graph_api_service.get_node_relationships(
            observable_information_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == observable_information_id:
                observable_information['relations'].append(
                    RelationInformation(second_node_id=relation["end_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))
            else:
                observable_information['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return ObservableInformationOut(**observable_information)
예제 #14
0
    def get_time_series(self, time_series_id: int):
        """
        Send request to graph api to get given time series

        Args:
            time_series_id (int): Id of time series

        Returns:
            Result of request as time series object
        """
        get_response = self.graph_api_service.get_node(time_series_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=time_series_id, errors=get_response["errors"])
        if get_response["labels"][0] != "Time Series":
            return NotFoundByIdModel(id=time_series_id, errors="Node not found.")

        time_series = {'id': get_response['id'], 'additional_properties': [], 'relations': [],
                             'reversed_relations': []}
        for property in get_response["properties"]:
            if property["key"] in ["type", "source"]:
                time_series[property["key"]] = property["value"]
            else:
                time_series['additional_properties'].append({'key': property['key'], 'value': property['value']})

        relations_response = self.graph_api_service.get_node_relationships(time_series_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == time_series_id:
                time_series['relations'].append(RelationInformation(second_node_id=relation["end_node"],
                                                                          name=relation["name"],
                                                                          relation_id=relation["id"]))
            else:
                time_series['reversed_relations'].append(RelationInformation(second_node_id=relation["start_node"],
                                                                                   name=relation["name"],
                                                                                   relation_id=relation["id"]))

        return TimeSeriesOut(**time_series)
예제 #15
0
    def get_scenario(self, node_id: int):
        """
        Send request to graph api to get activity executions and experiment from scenario

        Args:
            node_id (int): Id of experiment or activity execution which is included in scenario

        Returns:
            Result of request as Scenario object
        """
        get_response = self.graph_api_service.get_node(node_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=node_id, errors=get_response["errors"])
        if get_response["labels"][0] not in [
                "Activity Execution", "Experiment"
        ]:
            return NotFoundByIdModel(id=node_id, errors="Node not found.")

        if get_response["labels"][0] == "Activity Execution":
            return self.get_scenario_by_activity_execution(node_id)
        elif get_response["labels"][0] == "Experiment":
            return self.get_scenario_by_experiment(node_id)
    def get_experiment(self, experiment_id: int):
        """
        Send request to graph api to get given experiment

        Args:
        experiment_id (int): Id of experiment

        Returns:
            Result of request as experiment object
        """
        get_response = self.graph_api_service.get_node(experiment_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=experiment_id, errors=get_response["errors"])
        if get_response["labels"][0] != "Experiment":
            return NotFoundByIdModel(id=experiment_id, errors="Node not found.")

        experiment = {'id': get_response['id'], 'additional_properties': [], 'relations': [], 'reversed_relations': []}
        for property in get_response["properties"]:
            if property["key"] == "experiment_name":
                experiment[property["key"]] = property["value"]
            else:
                experiment['additional_properties'].append({'key': property['key'], 'value': property['value']})

        relations_response = self.graph_api_service.get_node_relationships(experiment_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == experiment_id:
                experiment['relations'].append(RelationInformation(second_node_id=relation["end_node"],
                                                                   name=relation["name"], relation_id=relation["id"]))
            else:
                experiment['reversed_relations'].append(RelationInformation(second_node_id=relation["start_node"],
                                                                            name=relation["name"],
                                                                            relation_id=relation["id"]))

        return ExperimentOut(**experiment)
    def get_activity_execution(self, activity_execution_id: int):
        """
        Send request to graph api to get given activity execution

        Args:
            activity_execution_id (int): Id of activity execution

        Returns:
            Result of request as activity execution object
        """
        get_response = self.graph_api_service.get_node(activity_execution_id)

        if get_response["errors"] is not None:
            return NotFoundByIdModel(id=activity_execution_id, errors=get_response["errors"])
        if get_response["labels"][0] != "Activity Execution":
            return NotFoundByIdModel(id=activity_execution_id, errors="Node not found.")

        activity_execution = {'id': get_response['id'], 'additional_properties': [], 'relations': [],
                              'reversed_relations': []}
        for property in get_response["properties"]:
            activity_execution['additional_properties'].append({'key': property['key'], 'value': property['value']})

        relations_response = self.graph_api_service.get_node_relationships(activity_execution_id)

        for relation in relations_response["relationships"]:
            if relation["start_node"] == activity_execution_id:
                activity_execution['relations'].append(RelationInformation(second_node_id=relation["end_node"],
                                                                           name=relation["name"],
                                                                           relation_id=relation["id"]))
            else:
                activity_execution['reversed_relations'].append(
                    RelationInformation(second_node_id=relation["start_node"],
                                        name=relation["name"],
                                        relation_id=relation["id"]))

        return ActivityExecutionOut(**activity_execution)