def addcases(cls, crd, disclosures): for case in disclosures: fine = case['renderedfine'] if not fine: fine = case['amendedfine'] if not fine: _search = re_DOLLARAMT.search(str(case['sanctions'])) if _search: fine = _search.group(1) row = mergedicts( { k: (floating_point(fine) if k == 'renderedfine' else pd.to_datetime(v) if k == 'date' else v) for k, v in case.items() if k in cls._meta.fields }, adviser=crd) entry = cls.get_or_create(**row)[0] if case['allegation']: try: Allegation.get_or_create(case=entry.id, allegation=re_ALLEGATION.sub( r'\1', case['allegation'])) except IntegrityError: pass
def parse_scheduleDjson(crd): data = [] try: adviser = db.Adviser.get(crd=crd) funds = adviser.privatefunds except (IOError, db.Adviser.DoesNotExist, KeyError): return data for fund in funds: row = { 'crd': crd, 'adviser': adviser.name, 'fund_id': fund['fund_id'], 'fundname': fund['name'], 'assetsundermgmt': floating_point(fund['fundinfo'].get('assetsundermgmt', 'n/a')), 'fundtype': fund['fundinfo'].get('fundtype', 'n/a'), 'owners': fund['fundinfo'].get('numberofowners', 'n/a'), } if 'businesses' in fund: for business in fund['businesses']: data.append(mergedicts(business, row)) return data
def insert_fund(crd, fund): info = fund['fundinfo'] _ = fund['fund_id'] row = mergedicts({ k : (v if k != 'assetsundermgmt' else floating_point(v)) for k, v in info.items() if k in db.PrivateFund._meta.fields }, type = info['fundtype'], fund_id = "{}-{}".format(_[0:3], _[3:]), adviser_id = crd, name = fund['name']) return db.PrivateFund.get_or_create(**row)[0]
def insert_courtcases(crd, data): _ = data['data'] if 'regulatory_drps' in _: disclosures = _['regulatory_drps'] for case in disclosures: row = mergedicts({ k : (floating_point(v) if k == 'rendered_fine' else v) for k, v in case.items() if k in db.Courtcase._meta.fields }, adviser = crd) entry = db.Courtcase.get_or_create(**row)[0] if case['allegation']: db.Allegation.insert( case = entry.id, allegation = case['allegation'] ).execute()
def addfund(cls, crd, fund): info = fund['fundinfo'] _ = fund['fund_id'] aum = info['assetsundermgmt'] if not aum: aum = 0 row = mergedicts( { k: (v if k != 'assetsundermgmt' else floating_point(aum)) for k, v in info.items() if k in cls._meta.fields }, type=info['fundtype'], fund_id="{}-{}".format(_[0:3], _[3:]), adviser_id=crd, name=fund['name']) try: entry = cls.get_or_create(**row) except IntegrityError as e: db_logger.error(e) return cls.get(adviser=crd, fund_id=row['fund_id']) return entry[0]