def person_properties_by_email(): """ Get a person properties by email This endpoint returns all properties of a person by a given EMAIL in a key/value fashion --- tags: - person parameters: - name: email in: query type: string description: email of person required: true responses: 200: description: A single user item schema: properties: property-1: type: string description: A property default: 'value-1' property-2: type: string description: A property default: 'value-2' property-N: type: string description: A property default: 'value-N' 400: description: Bad request. Missing/wrong parameter. 404: description: Person not found """ email = request.args.get('email', None) if email is None: return 'No email provided', 400 person = Store.get_person({"email": email}) if person is None: return 'Person with email %s not found' % email, 404 data = person.get_properties() data['aid'] = person.aid response = app.response_class(response=json.dumps(data), status=200, mimetype='application/json') return response
def get_relations(self, filter=None): """ Looks at raw data of person entity and returns all relations. :return: List of tupples, each tupple: (target_aid, relationship type, relationship properties) """ from store.store import Store relations = set() # C:C - Create ACQUIRED_BY relation if C.ACQUIRED_BY in self.deduced: #acquiring_company = Store.get_company({C.NAME: self.deduced[C.ACQUIRED_BY]}) acquiring_company = Store.get_company( {C.ALIASES: self.deduced[C.ACQUIRED_BY].lower()}) if acquiring_company: relations.add((self.aid, G.RELATION_LABEL_ACQUIRED_BY, acquiring_company.aid, '')) # C:C - Create the INVESTED_IN relation if C.ORGANIZATION_TYPE in self.deduced and self.deduced[ C.ORGANIZATION_TYPE] == C.ORGANIZATION_TYPE_VENTURE_CAPITAL: for portfolio_company in self.deduced.get(C.PORTFOLIO_COMPANIES, []): ccc_company = Store.get_company( {C.ALIASES: portfolio_company.lower()}) if ccc_company: relations.add((self.aid, G.RELATION_LABEL_INVESTS_IN, ccc_company.aid, '')) # P:C - Create EMPLOYEE_OF relation (Team. past_team) for team_mate in self.deduced.get(C.TEAM, []): person = Store.get_person({P.FULL_NAME: team_mate}) if person: relations.add( (person.aid, G.RELATION_LABEL_EMPLOYEE_OF, self.aid, '')) # P:C - Create BOARD_AT relation (Advisors) for advisor in self.deduced.get(C.ADVISORS, []): person = Store.get_person({P.FULL_NAME: advisor}) if person: relations.add( (person.aid, G.RELATION_LABEL_ADVISOR_AT, self.aid, '')) # P:C - Create FOUNDER_OF relation (Company) for founder in self.deduced.get(C.FOUNDERS, []): person = Store.get_person({P.FULL_NAME: founder}) if person: relations.add( (person.aid, G.RELATION_LABEL_FOUNDER_OF, self.aid, '')) # P:C - Create INVESTS_AT relation (Investors) for investor_name, investor_type, investment_info in self.deduced.get( C.INVESTORS, []): # Find info on investment type -> relation_properties relation_properties = [] investment_round = AcureRateUtils.get_investment_round( investment_info) if investment_round: relation_properties.append("investment_type: '%s'" % investment_round) investment_lead = AcureRateUtils.is_investment_lead( investment_info) if investment_lead: # TODO: should be label and not property relation_properties.append("investment_lead: True") if investor_type == 'person': person = Store.get_person( {'deduced.' + P.FULL_NAME: investor_name}) if person: relations.add((person.aid, G.RELATION_LABEL_INVESTS_IN, self.aid, ', '.join(relation_properties))) elif investor_type == 'organization': investing_company = Store.get_company({C.NAME: investor_name}) if investing_company: relations.add( (investing_company.aid, G.RELATION_LABEL_INVESTS_IN, self.aid, ', '.join(relation_properties))) # If filter provided, leave only relations that are relevant if filter: relations = [ tup for tup in relations if tup[1].lower() == filter.lower() ] return relations
def person_relations_by_email(): """ Get a person relations by email This endpoint returns all properties of a person by a given EMAIL in a key/value fashion --- tags: - person parameters: - name: email in: query type: string description: email of person required: true - name: filter in: query type: string description: relation type to use as filter (case-insensitive) responses: 200: description: A single user item schema: properties: property-1: type: string description: A property default: 'value-1' property-2: type: string description: A property default: 'value-2' property-N: type: string description: A property default: 'value-N' 400: description: Bad request. Missing/wrong parameter. 404: description: Person not found """ email = request.args.get('email', None) if email is None: return 'No email provided', 400 person = Store.get_person({"email": email}) if person is None: return 'Person with email %s not found' % email, 404 filter = request.args.get('filter', None) relations = person.get_relations(filter) data = [] for source_aid, relation_type, target_aid, relation_properties in relations: # TODO: move relation_properties from string to array data_element = { 'relation_type': relation_type, 'relation_properties': relation_properties, 'source_id': source_aid, 'target_id': target_aid } data.append(data_element) response = app.response_class(response=json.dumps(data), status=200, mimetype='application/json') return response