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

Adding support for new tracker model. #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
dist/
env/
pydas.egg-info
.idea
196 changes: 60 additions & 136 deletions pydas/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,80 +1233,47 @@ def solr_advanced_search(self, query, token=None, limit=20):
class TrackerDriver(BaseDriver):
"""Driver for the tracker module API methods."""

def associate_item_with_scalar_data(self, token, item_id, scalar_id,
label):
def associate_item_with_submission(self, token, item_id, submission_id,
label):
"""
Associate a result item with a particular scalar value.

:param token: A valid token for the user in question.
:type token: string
:param item_id: The id of the item to associate with the scalar.
:type item_id: int | long
:param scalar_id: Scalar id with which to associate the item.
:type scalar_id: int | long
:param submission_id: Submission id with which to associate the item.
:type submission_id: int | long
:param label: The label describing the nature of the association.
:type label: string
"""
parameters = dict()
parameters['token'] = token
parameters['scalarIds'] = scalar_id
parameters['submissionId'] = submission_id
parameters['itemId'] = item_id
parameters['label'] = label
self.request('midas.tracker.item.associate', parameters)

def create_submission(self, token, **kwargs):
def create_submission(self, token, community_id, producer_display_name, producer_revision, submit_time, **kwargs):
"""
Associate a result item with a particular scalar value.

:param token: A valid token for the user in question.
:type token: string
:param community_id: The id of the community that owns the producer.
:type community_id: int | long
:param producer_display_name: The display name of the producer.
:type producer_display_name: str
:param uuid (optional) The uuid of the submission (must be unique)
:type uuid: string
:param name (optional) The name of the submission
:type name: string
:returns: The submission object that was created.
:rtype: dict
"""
parameters = {}
parameters['token'] = token
optional_keys = ['uuid', 'name']
for key in optional_keys:
if key in kwargs:
parameters[key] = kwargs[key]
return self.request('midas.tracker.submission.create', parameters)

def add_scalar_data(self, token, community_id, producer_display_name,
metric_name, producer_revision, submit_time, value,
**kwargs):
"""
Create a new scalar data point.

:param token: A valid token for the user in question.
:type token: string
:param community_id: The id of the community that owns the producer.
:type community_id: int | long
:param producer_display_name: The display name of the producer.
:type producer_display_name: string
:param metric_name: The metric name that identifies which trend this
point belongs to.
:type metric_name: string
:param producer_revision: The repository revision of the producer that
produced this value.
:type producer_revision: int | long | string
:param submit_time: The submit timestamp. Must be parsable with PHP
strtotime().
:type submit_time: string
:param value: The value of the scalar.
:type value: float
:param config_item_id: (optional) If this value pertains to a specific
configuration item, pass its id here.
:type config_item_id: int | long
:param test_dataset_id: (optional) If this value pertains to a
specific test dataset, pass its id here.
:type test_dataset_id: int | long
:param truth_dataset_id: (optional) If this value pertains to a
specific ground truth dataset, pass its id here.
:type truth_dataset_id: int | long
:param silent: (optional) If true, do not perform threshold-based email
notifications for this scalar.
:type silent: bool
Expand All @@ -1332,113 +1299,83 @@ def add_scalar_data(self, token, community_id, producer_display_name,
with this scalar result. Each element of the list should be a dict
with the following keys: label, text, href
:type extra_urls: list[dict]
:param unit: (optional) The unit of the scalar value.
:type unit: string
:param reproduction_command: (optional) The command to reproduce this
scalar.
:type reproduction_command: string
:returns: The scalar object that was created.
:returns: The submission object that was created.
:rtype: dict
"""
parameters = dict()
parameters['token'] = token
parameters['communityId'] = community_id
parameters['producerDisplayName'] = producer_display_name
parameters['metricName'] = metric_name
parameters['producerRevision'] = producer_revision
parameters['submitTime'] = submit_time
parameters['value'] = value
optional_keys = [
'config_item_id', 'test_dataset_id', 'truth_dataset_id', 'silent',
'unofficial', 'build_results_url', 'branch', 'extra_urls',
'params', 'submission_id', 'submission_uuid', 'unit',
'reproduction_command'
]
parameters = {
'token': token,
'producerRevision': producer_revision,
'submitTime': submit_time,
'communityId': community_id,
'producerDisplayName': producer_display_name
}

optional_keys = ['uuid', 'name', 'unofficial', 'build_results_url',
'branch', 'extra_urls', 'params', 'reproduction_command']
for key in optional_keys:
if key in kwargs:
if key == 'config_item_id':
parameters['configItemId'] = kwargs[key]
elif key == 'test_dataset_id':
parameters['testDatasetId'] = kwargs[key]
elif key == 'truth_dataset_id':
parameters['truthDatasetId'] = kwargs[key]
if key == 'reproduction_command':
parameters['reproductionCommand'] = kwargs[key]
elif key == 'build_results_url':
parameters['buildResultsUrl'] = kwargs[key]
elif key == 'extra_urls':
parameters['extraUrls'] = json.dumps(kwargs[key])
elif key == 'reproduction_command':
parameters['reproductionCommand'] = kwargs[key]
elif key == 'params':
parameters[key] = json.dumps(kwargs[key])
elif key == 'silent':
if kwargs[key]:
parameters[key] = kwargs[key]
elif key == 'unofficial':
if kwargs[key]:
parameters[key] = kwargs[key]
elif key == 'submission_id':
parameters['submissionId'] = kwargs[key]
elif key == 'submission_uuid':
parameters['submissionUuid'] = kwargs[key]
elif key == 'unit':
parameters['unit'] = kwargs[key]
elif key == 'reproduction_command':
parameters['reproductionCommand'] = kwargs[key]
else:
parameters[key] = kwargs[key]
response = self.request('midas.tracker.scalar.add', parameters)
return response
return self.request('midas.tracker.submission.add', parameters)

def upload_json_results(self, token, filepath, community_id,
producer_display_name, metric_name,
producer_revision, submit_time, **kwargs):
def add_scalar_data(self, token, community_id, producer_display_name,
metric_name, value, submission_uuid, **kwargs):
"""
Upload a JSON file containing numeric scoring results to be added as
scalars. File is parsed and then deleted from the server.
Create a new scalar data point.

:param token: A valid token for the user in question.
:param filepath: The path to the JSON file.
:type token: str
:param community_id: The id of the community that owns the producer.
:type community_id: int | long
:param producer_display_name: The display name of the producer.
:param producer_revision: The repository revision of the producer
that produced this value.
:param submit_time: The submit timestamp. Must be parsable with PHP
strtotime().
:type producer_display_name: str
:param metric_name: The metric name that identifies which trend this
point belongs to.
:type metric_name: str
:param config_item_id: (optional) If this value pertains to a specific
configuration item, pass its id here.
:type config_item_id: int | long
:param test_dataset_id: (optional) If this value pertains to a
specific test dataset, pass its id here.
:type test_dataset_id: int | long
:param truth_dataset_id: (optional) If this value pertains to a
specific ground truth dataset, pass its id here.
:param parent_keys: (optional) Semicolon-separated list of parent keys
to look for numeric results under. Use '.' to denote nesting, like
in normal javascript syntax.
:param silent: (optional) If true, do not perform threshold-based email
notifications for this scalar.
:param unofficial: (optional) If true, creates an unofficial scalar
visible only to the user performing the submission.
:param build_results_url: (optional) A URL for linking to build results
for this submission.
:param branch: (optional) The branch name in the source repository for
this submission.
:param params: (optional) Any key/value pairs that should be displayed
with this scalar result.
:type params: dict
:param extra_urls: (optional) Other URL's that should be displayed with
with this scalar result. Each element of the list should be a dict
with the following keys: label, text, href
:type extra_urls: list of dicts
:returns: The list of scalars that were created.
:type truth_dataset_id: int | long
:param value: The value of the scalar.
:type value: float
:param submission_uuid: The UUID of the submission.
:type submission_uuid: str
:param unit: (optional) The unit of the scalar value.
:type unit: string
:returns: The scalar object that was created.
:rtype: dict
"""
parameters = dict()
parameters['token'] = token
parameters['communityId'] = community_id
parameters['producerDisplayName'] = producer_display_name
parameters['metricName'] = metric_name
parameters['producerRevision'] = producer_revision
parameters['submitTime'] = submit_time
optional_keys = [
'config_item_id', 'test_dataset_id', 'truth_dataset_id', 'silent',
'unofficial', 'build_results_url', 'branch', 'extra_urls',
'params']
parameters = {
'token': token,
'metricName': metric_name,
'submissionUuid': submission_uuid,
'value': value,
'communityId': community_id,
'producerDisplayName': producer_display_name
}
optional_keys = ['config_item_id', 'test_dataset_id',
'truth_dataset_id', 'unit']
for key in optional_keys:
if key in kwargs:
if key == 'config_item_id':
Expand All @@ -1447,23 +1384,10 @@ def upload_json_results(self, token, filepath, community_id,
parameters['testDatasetId'] = kwargs[key]
elif key == 'truth_dataset_id':
parameters['truthDatasetId'] = kwargs[key]
elif key == 'parent_keys':
parameters['parentKeys'] = kwargs[key]
elif key == 'build_results_url':
parameters['buildResultsUrl'] = kwargs[key]
elif key == 'extra_urls':
parameters['extraUrls'] = json.dumps(kwargs[key])
elif key == 'params':
parameters[key] = json.dumps(kwargs[key])
elif key == 'silent':
if kwargs[key]:
parameters[key] = kwargs[key]
elif key == 'unofficial':
if kwargs[key]:
parameters[key] = kwargs[key]
elif key == 'unit':
parameters['unit'] = kwargs[key]
else:
parameters[key] = kwargs[key]
file_payload = open(filepath, 'rb')
response = self.request('midas.tracker.results.upload.json',
parameters, file_payload)
response = self.request('midas.tracker.scalar.add', parameters)
return response