Giter VIP home page Giter VIP logo

dmponline's Introduction

DMPonline

A Python interface to the DMPonline API. For API documentation, see https://github.com/DMPRoadmap/roadmap/wiki/API-documentation.

Installation:

pip install dmponline

Usage example:

from dmponline import DMPonline

# initialize DMPonline class
dmp_api = DMPonline(<YOUR-DMPONLINE-API-TOKEN>, token_user=<YOUR-DMPONLINE-USER-EMAIL>)
# retreive pandas dataframe with all DMPs in your organization
dmps = dmp_api.plan_statistics(params={'remove_tests': 'false'})

Command line

The package also ships a command line script to retreive an overview of all questions in a particular DMP.

Usage example:

question_overview -i DMPONLINE_PLAN_ID -t <YOUR-DMPONLINE-API-TOKEN>

Retrieving structured DMP:s

If your organization has enabled question id feature for DMPOnline for templates you can retrieve structured DMP:s using the following script snippet. Remember to modify the template ID

from src import dmponline
import json


dmp_api = dmponline.DMPonline(url="https://dmptuuli.fi/api/",token="your-dmponline-token")

plans = dmp_api.get_plans(params={'template':'1440979378'})

for plan in plans['plans']:
    for content in plan['plan_content']:
        dmp = {
            'id':plan['id'],
            'title':plan['title'],
            'last_updated':plan['last_updated'],
            'created':plan['creation_date']
            }
        if plan.get("principal_investigator"):
            dmp["principal_investigator"] = plan.get("principal_investigator")
        if plan.get("data_contact"):
            dmp["data_contact"] = plan.get("data_contact")
        if plan.get("users"):
            dmp["users"] = plan.get("users")
        if plan.get("grant_number"):
            dmp["grant_number"] = plan.get("grant_number")
        if plan.get("funder"):
            dmp["funder"] = plan.get("funder")
            
        question_data = {}
        for section in content['sections']:
    
            for question in section['questions']:
                selected = []
                if len(question['question_identifiers'])>0:
                    for identifier in question['question_identifiers']:
                        if identifier['name'] == 'tuni/v1':
                            name = identifier['name'] + "::" + identifier['value']
                            if question.get("answer"):
                                options = question.get("answer").get("options")
                                if options:
                                    for option in options:
                                        selected.append(option.get("answer_identifier"))
                                        question_data[name] = selected
                                else:
                                    answer_text = question.get("answer").get("text")
                                    question_data[name] = answer_text
                                
        dmp["dmp"] = question_data
    if question_data:
        with open(str(plan['id'])+".json", "w") as outfile: 
            json.dump(dmp, outfile,indent=2)
                    

dmponline's People

Contributors

heijer avatar mjlassila avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.