Exemplo n.º 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)
Exemplo n.º 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)
    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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
    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)