Commit b6a94b04 authored by abuddenberg's avatar abuddenberg
Browse files

Contributors will now correctly populate

parent 865ab73c
...@@ -3,16 +3,15 @@ __author__ = 'abuddenberg' ...@@ -3,16 +3,15 @@ __author__ = 'abuddenberg'
from gcis_clients import WebformClient from gcis_clients import WebformClient
from gcis_clients import GcisClient from gcis_clients import GcisClient
from gcis_clients.sync_utils import move_images_to_gcis, sync_dataset_metadata, populate_contributors from gcis_clients.sync_utils import move_images_to_gcis, sync_dataset_metadata, realize_contributors
from collections import OrderedDict from collections import OrderedDict
import json import json
import pickle import pickle
webform = WebformClient('http://resources.assessment.globalchange.gov', 'mgTD63FAjG') webform = WebformClient('http://resources.assessment.globalchange.gov', 'mgTD63FAjG')
gcis_url = 'http://data.gcis-dev-front.joss.ucar.edu' # gcis = GcisClient('http://data.gcis-dev-front.joss.ucar.edu', 'andrew.buddenberg@noaa.gov', 'ad90c05b37d4128ae514bc6caa7a41911d2f1de353443a54')
gcis = GcisClient(gcis_url, 'andrew.buddenberg@noaa.gov', 'ad90c05b37d4128ae514bc6caa7a41911d2f1de353443a54') gcis = GcisClient('http://data-stage.globalchange.gov', 'andrew.buddenberg@noaa.gov', 'b4f1458c3cf28248c982428c46e170019327bd4c533c23dd')
# gcis = GcisClient('http://data-stage.globalchange.gov', 'andrew.buddenberg@noaa.gov', 'b4f1458c3cf28248c982428c46e170019327bd4c533c23dd')
sync_metadata_tree = { sync_metadata_tree = {
#Reports #Reports
...@@ -64,7 +63,7 @@ sync_metadata_tree = { ...@@ -64,7 +63,7 @@ sync_metadata_tree = {
]), ]),
#Chapter 9 #Chapter 9
('human-health', [ ('human-health', [
('/metadata/figures/2896', 'heavy-downpours-disease') #Needs images redone ('/metadata/figures/2896', 'heavy-downpours-disease')
]), ]),
#Chapter 10 #Chapter 10
('water-energy-land-use', [ ('water-energy-land-use', [
...@@ -82,7 +81,7 @@ sync_metadata_tree = { ...@@ -82,7 +81,7 @@ sync_metadata_tree = {
]), ]),
#Chapter 14 #Chapter 14
('rural', [ ('rural', [
('/metadata/figures/3306', 'growing-season-lengthens') #Needs images redone ('/metadata/figures/3306', 'growing-season-lengthens')
]), ]),
# Chapter 15 # Chapter 15
('biogeochemical-cycles', [ ('biogeochemical-cycles', [
...@@ -92,7 +91,7 @@ sync_metadata_tree = { ...@@ -92,7 +91,7 @@ sync_metadata_tree = {
('northeast', [ ('northeast', [
('/metadata/figures/2995', 'projected-increases-in-the-number-of-days-over-90f'), ('/metadata/figures/2995', 'projected-increases-in-the-number-of-days-over-90f'),
('/metadata/figures/2844', 'coney-island-after-hurricane-irene'), ('/metadata/figures/2844', 'coney-island-after-hurricane-irene'),
('/metadata/figures/2846', 'storm-surge-barrier') #Wrong figurenum in GCIS ('/metadata/figures/2846', 'storm-surge-barrier')
]), ]),
#Chapter 17 #Chapter 17
('southeast', [ ('southeast', [
...@@ -122,7 +121,7 @@ sync_metadata_tree = { ...@@ -122,7 +121,7 @@ sync_metadata_tree = {
('appendix-climate-science', [ ('appendix-climate-science', [
('/metadata/figures/3301', 'human-influences-apparent-in-many-aspects-of-the-changing-climate'), ('/metadata/figures/3301', 'human-influences-apparent-in-many-aspects-of-the-changing-climate'),
('/metadata/figures/2798', 'detection-and-attribution-as-forensics'), ('/metadata/figures/2798', 'detection-and-attribution-as-forensics'),
('/metadata/figures/2799', 'human-influences-apparent-in-many-climate-variables'), # ('/metadata/figures/2799', 'human-influences-apparent-in-many-climate-variables'), #Dupe, not used
('/metadata/figures/2802', 'modeling-the-climate-system'), ('/metadata/figures/2802', 'modeling-the-climate-system'),
('/metadata/figures/2803', 'increasing-model-resolution'), ('/metadata/figures/2803', 'increasing-model-resolution'),
('/metadata/figures/2533', 'us-seasonal-temperatures'), ('/metadata/figures/2533', 'us-seasonal-temperatures'),
...@@ -142,19 +141,9 @@ sync_metadata_tree = { ...@@ -142,19 +141,9 @@ sync_metadata_tree = {
def main(): def main():
# print gcis.test_login() # print gcis.test_login()
# sync_dataset_metadata(aggregate_webform_datasets()) # sync_dataset_metadata(gcis, webform.get_aggregated_datasets(), skip=['Proxy Data', 'Projected Sea Level Rise', 'Tide Gauge Data'])
sync(replace=False) sync(replace=False)
# s = 'Vose, R.S., S. Applequist, M.A. Bourassa, S.C. Pryor, R.J. Barthelmie, B. Blanton, P.D. Bromirski, H.E. Brooks, A.T. D,'
#
# for author in s.split(','):
# frags = author.strip().rsplit()
# if len(frags) > 0 and len(frags[-1]) > 1:
# # print frags
# print '{t}: {r}'.format(t=frags[-1], r=gcis.lookup_person(frags[-1]))
def sync(replace=False): def sync(replace=False):
...@@ -163,32 +152,33 @@ def sync(replace=False): ...@@ -163,32 +152,33 @@ def sync(replace=False):
for figure_ids in sync_metadata_tree[report_id][chapter_id]: for figure_ids in sync_metadata_tree[report_id][chapter_id]:
webform_url, gcis_id = figure_ids webform_url, gcis_id = figure_ids
print 'Attempting to sync: {id}'.format(id=gcis_id), ' ', webform_url print 'Attempting to sync: {id}'.format(id=gcis_id), webform_url
f = webform.get_webform(webform_url) #Merge data from both systems into one object...
populate_contributors(gcis, f.contributors) gcis_fig = gcis.get_figure(report_id, gcis_id, chapter_id=chapter_id)
print f.contributors figure_obj = webform.get_webform(webform_url).merge(gcis_fig)
# #Merge data from both systems into one object... #Lookup and populate contributor information for figures and images
# gcis_fig = gcis.get_figure(report_id, gcis_id, chapter_id=chapter_id) realize_contributors(gcis, figure_obj.contributors)
# figure_obj = webform.get_webform(webform_url).merge(gcis_fig) for i in figure_obj.images:
# realize_contributors(gcis, i.contributors)
# #Hack: override webform's title in favor of gcis
# figure_obj.title = gcis_fig.title if gcis_fig.title not in (None, '') else figure_obj.title #Hack: override webform's title in favor of gcis
# figure_obj.title = gcis_fig.title if gcis_fig.title not in (None, '') else figure_obj.title
# if replace:
# for image in figure_obj.images: if replace:
# #TODO: There are better ways to do this. Build File support. for image in figure_obj.images:
# print 'Deleting {img}'.format(img=image.identifier) #TODO: There are better ways to do this. Build File support.
# gcis.delete_image(image) print 'Deleting {img}'.format(img=image.identifier)
# gcis.delete_image(image)
# print 'Attempting to upload: {id}'.format(id=gcis_id)
# move_images_to_gcis(webform, gcis, webform_url, gcis_id, report_id) print 'Attempting to upload: {id}'.format(id=gcis_id)
# move_images_to_gcis(webform, gcis, webform_url, gcis_id, report_id)
# #...then send it.
# gcis.update_figure(report_id, chapter_id, figure_obj) #...then send it.
# gcis.update_figure(report_id, chapter_id, figure_obj)
# print 'Success!'
print 'Success!'
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -44,16 +44,10 @@ def realize_contributors(gcis_client, contributors): ...@@ -44,16 +44,10 @@ def realize_contributors(gcis_client, contributors):
print '\t\t', name_matches print '\t\t', name_matches
if org.identifier in (None, '') and org.name not in (None, ''): if org.identifier in (None, '') and org.name not in (None, ''):
print 'No ID found for ' + org.name
# if org.name not in (None, ''): print 'No ID found for ' + org.name
# org_matches = gcis_client.lookup_organization(org.name)
# if len(org_matches) == 1:
# org.identifier = org_matches[0][0]
# elif len(org_matches) == 0:
# print 'No ID found for ' + org.name
# else:
# print 'Ambiguous results for ' + org.name
# print '\t', org_matches
#Check if we missed any organizations in our hardcoding...
if not all(map(lambda c: c.organization.identifier is not None, contributors)):
print contributors
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment