Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bill sponsor #67

Merged
merged 27 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
favicon changed
  • Loading branch information
kapphire committed Nov 26, 2020
commit a43c34b20767a7e65a5c21eec17a043d63a0c42b
119 changes: 64 additions & 55 deletions server_py/flatgov/common/relatedBills.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,73 +28,82 @@ def addSimilarTitles(noYearTitlesIndex: dict, billsRelated = {}):
totalTitles = len(noYearTitlesIndex)
titleNum = 0
for title, bills in noYearTitlesIndex.items():
titleNum += 1
logger.info('Adding noYearTitle: ' + title)
logger.info(str(titleNum) +' of ' + str(totalTitles))
relatedBills = { bill: loadRelatedBillJSON(bill) for bill in bills}
relatedTitles = { bill: list(filter(lambda titleItem: titleItem.startswith(title), deep_get(BILLS_META, bill, 'titles'))) for bill in bills}
for bill_outer in relatedBills:
for bill_inner in relatedBills:
similarTitle = relatedTitles.get(bill_inner)
if similarTitle and len(similarTitle) == 1:
similarTitle = similarTitle[0]
else:
continue
# Find a matching item, if any, in the list billsRelated[bill_outer]
if not deep_get(relatedBills, bill_outer, 'related', bill_inner):
relatedBills[bill_outer]['related'][bill_inner] = {
'titles_year': [similarTitle]
}
elif not deep_get(relatedBills, bill_outer, 'related', bill_inner, 'titles_year'):
relatedBills[bill_outer]['related'][bill_inner]['titles_year'] = [similarTitle]
else:
if similarTitle not in relatedBills[bill_outer]['related'][bill_inner]['titles_year']:
try:
relatedBills[bill_outer]['related'][bill_inner]['titles_year'].append(similarTitle)
except:
try:
titleNum += 1
logger.info('Adding noYearTitle: ' + title)
logger.info(str(titleNum) +' of ' + str(totalTitles))
relatedBills = { bill: loadRelatedBillJSON(bill) for bill in bills}
relatedTitles = { bill: list(filter(lambda titleItem: titleItem.startswith(title), deep_get(BILLS_META, bill, 'titles'))) for bill in bills}
for bill_outer in relatedBills:
for bill_inner in relatedBills:
similarTitle = relatedTitles.get(bill_inner)
if similarTitle and len(similarTitle) == 1:
similarTitle = similarTitle[0]
else:
continue
# Find a matching item, if any, in the list billsRelated[bill_outer]
if not deep_get(relatedBills, bill_outer, 'related', bill_inner):
relatedBills[bill_outer]['related'][bill_inner] = {
'titles_year': [similarTitle]
}
elif not deep_get(relatedBills, bill_outer, 'related', bill_inner, 'titles_year'):
relatedBills[bill_outer]['related'][bill_inner]['titles_year'] = [similarTitle]

if deep_get(relatedBills, bill_outer, 'related', bill_inner, 'titles_year'):
logger.debug(relatedBills[bill_outer]['related'][bill_inner])
dumpRelatedBillJSON(bill_outer, relatedBills.get(bill_outer))
else:
if similarTitle not in relatedBills[bill_outer]['related'][bill_inner]['titles_year']:
try:
relatedBills[bill_outer]['related'][bill_inner]['titles_year'].append(similarTitle)
except:
relatedBills[bill_outer]['related'][bill_inner]['titles_year'] = [similarTitle]

if deep_get(relatedBills, bill_outer, 'related', bill_inner, 'titles_year'):
logger.debug(relatedBills[bill_outer]['related'][bill_inner])
dumpRelatedBillJSON(bill_outer, relatedBills.get(bill_outer))
except Exception as e:
continue
logger.info('*** Finished Adding NoYear Titles ***')

def addSameTitles(titlesIndex: dict):
for title, bills in titlesIndex.items():
for bill_outer in bills:
logger.debug('Adding related titles: ' + bill_outer)
billRelated = loadRelatedBillJSON(bill_outer)
for bill_inner in bills:
# Find a matching item, if any, in the list billRelated
if not deep_get(billRelated, 'related'):
billRelated['related'] = {}
if not deep_get(billRelated, 'related', bill_inner):
billRelated['related'][bill_inner] = {'titles': [title]}
elif title not in deep_get(billRelated, 'related', bill_inner, 'titles'):
billRelated['related'][bill_inner]['titles'].append(title)
logger.debug('Saving with related titles: ' + bill_outer)
dumpRelatedBillJSON(bill_outer, billRelated)
try:
logger.debug('Adding related titles: ' + bill_outer)
billRelated = loadRelatedBillJSON(bill_outer)
for bill_inner in bills:
# Find a matching item, if any, in the list billRelated
if not deep_get(billRelated, 'related'):
billRelated['related'] = {}
if not deep_get(billRelated, 'related', bill_inner):
billRelated['related'][bill_inner] = {'titles': [title]}
elif title not in deep_get(billRelated, 'related', bill_inner, 'titles'):
billRelated['related'][bill_inner]['titles'].append(title)
logger.debug('Saving with related titles: ' + bill_outer)
dumpRelatedBillJSON(bill_outer, billRelated)
except Exception as e:
continue
logger.info('*** Finished Adding Same Titles ***')

def addGPORelatedBills():
for bill_outer in ALL_BILLS:
billRelated = loadRelatedBillJSON(bill_outer)
billData = loadDataJSON(bill_outer)
if not billData or not deep_get(billData, 'related_bills'):
continue
try:
billRelated = loadRelatedBillJSON(bill_outer)
billData = loadDataJSON(bill_outer)
if not billData or not deep_get(billData, 'related_bills'):
continue

relatedBillItems = deep_get(billData, 'related_bills')
relatedBillItems = deep_get(billData, 'related_bills')

for billItem in relatedBillItems:
bill_inner = billIdToBillNumber(billItem.get('bill_id'))
newDict = {'reason': billItem.get('reason'), 'identified_by': billItem.get('identified_by')}
logger.debug(newDict)
# Find a matching item, if any, in the list billsRelated[bill_outer]
if not deep_get(billRelated, 'related', bill_inner):
billRelated['related'][bill_inner] = newDict
else:
billRelated['related'][bill_inner].update(newDict)
dumpRelatedBillJSON(bill_outer, billRelated)
for billItem in relatedBillItems:
bill_inner = billIdToBillNumber(billItem.get('bill_id'))
newDict = {'reason': billItem.get('reason'), 'identified_by': billItem.get('identified_by')}
logger.debug(newDict)
# Find a matching item, if any, in the list billsRelated[bill_outer]
if not deep_get(billRelated, 'related', bill_inner):
billRelated['related'][bill_inner] = newDict
else:
billRelated['related'][bill_inner].update(newDict)
dumpRelatedBillJSON(bill_outer, billRelated)
except Exception as e:
continue


def addSponsors():
Expand Down
4 changes: 2 additions & 2 deletions server_py/flatgov/flatgov/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

PATH_TO_BILLS_META = os.path.join(BASE_DIR, 'billsMeta.json')
PATH_TO_CONGRESSDATA_DIR = CONGRESS_DATA_PATH
PATH_TO_DATA_DIR = os.path.join('/', *"/usr/local/share/xcential/public/data".split('/'))
PATH_TO_CONGRESSDATA_XML_DIR = os.path.join('/', *"/usr/local/share/xcential/public/data/116/dtd".split('/'))
PATH_TO_DATA_DIR = os.getenv('PATH_TO_DATA_DIR', os.path.join('/', *"/usr/local/share/xcential/public/data".split('/')))
PATH_TO_CONGRESSDATA_XML_DIR = os.getenv('PATH_TO_CONGRESSDATA_XML_DIR', os.path.join('/', *"/usr/local/share/xcential/public/data/116/dtd".split('/')))
PATH_TO_BILLS_LIST = os.path.join(PATH_TO_CONGRESSDATA_DIR, 'billList.json')
PATH_TO_TITLES_INDEX = os.path.join(PATH_TO_CONGRESSDATA_DIR, 'titlesIndex.json')
PATH_TO_NOYEAR_TITLES_INDEX = os.path.join(PATH_TO_CONGRESSDATA_DIR, 'noYearTitlesIndex.json')
Expand Down
Binary file modified server_py/flatgov/static/favicon.ico
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1 change: 1 addition & 0 deletions server_py/flatgov/static/favicon_io/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}