Skip to content
Snippets Groups Projects
Commit 7de831ba authored by Nico Vermaas's avatar Nico Vermaas
Browse files

updating add_dataproducts functionality

parent dbe1879d
No related branches found
No related tags found
No related merge requests found
Pipeline #7287 passed
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<orderEntry type="jdk" jdkName="Python 3.7 (atdb-ldv)" jdkType="Python SDK" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (atdb-ldv) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="PyDocumentationSettings"> <component name="PyDocumentationSettings">
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (atdb-ldv)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (atdb-ldv) (2)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser"> <component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" /> <option name="shown" value="true" />
</component> </component>
......
...@@ -115,7 +115,6 @@ class DataProduct(TaskObject): ...@@ -115,7 +115,6 @@ class DataProduct(TaskObject):
description = models.CharField(max_length=255, default="unknown") description = models.CharField(max_length=255, default="unknown")
dataproduct_type = models.CharField('type', default=TYPE_VISIBILITY, max_length=50) dataproduct_type = models.CharField('type', default=TYPE_VISIBILITY, max_length=50)
size = models.BigIntegerField(default=0) size = models.BigIntegerField(default=0)
#quality = models.CharField(max_length=30, default="unknown")
# relationships # relationships
parent = models.ForeignKey(Observation, related_name='generated_dataproducts', on_delete=models.CASCADE, null=False) parent = models.ForeignKey(Observation, related_name='generated_dataproducts', on_delete=models.CASCADE, null=False)
......
...@@ -29,9 +29,9 @@ class DataProductSerializer(serializers.ModelSerializer): ...@@ -29,9 +29,9 @@ class DataProductSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = DataProduct model = DataProduct
fields = ('id','task_type','name','filename','description', fields = ('id','task_type','name','filename','description',
'taskID','creationTime','size','quality', 'taskID','creationTime','size',
'my_status','new_status','status_history','parent', 'my_status','new_status','status_history','parent',
'data_location','node') 'data_location','node','quality','metadata')
class ObservationSerializer(serializers.ModelSerializer): class ObservationSerializer(serializers.ModelSerializer):
......
...@@ -115,22 +115,26 @@ def get_next_observation(my_status, observing_mode, datawriter): ...@@ -115,22 +115,26 @@ def get_next_observation(my_status, observing_mode, datawriter):
return taskID,minutes_left return taskID,minutes_left
# /atdb/post_dataproducts?taskid=190405001 # /atdb/post_dataproducts
@timeit def add_dataproducts(dataproducts):
def add_dataproducts(taskID, dataproducts):
""" """
:param taskID: taskid of the observation :param taskID: taskid of the observation
:param dataproducts: json list of dataproducts to be added to the provided taskid :param dataproducts: json list of dataproducts to be added to the provided taskid
:return: :return:
""" """
number_of_dataproducts = len(dataproducts)
logger.info("add_dataproducts("+taskID+','+str(number_of_dataproducts)+")")
taskID = None
dps = dataproducts.get('dps')
number_of_dataproducts = len(dps)
logger.info("add_dataproducts("+str(number_of_dataproducts)+")")
for dp in dps:
# get the common fields from the observation based on the given taskid # get the common fields from the observation based on the given taskid
taskID = dp.get('taskID')
parent = Observation.objects.get(taskID=taskID) parent = Observation.objects.get(taskID=taskID)
parent_data_location = parent.data_location parent_data_location = parent.data_location
for dp in dataproducts:
node=dp.get('node',None) node=dp.get('node',None)
new_status = dp.get('new_status','defined') new_status = dp.get('new_status','defined')
data_location = dp.get('data_dir',parent_data_location) data_location = dp.get('data_dir',parent_data_location)
...@@ -141,6 +145,8 @@ def add_dataproducts(taskID, dataproducts): ...@@ -141,6 +145,8 @@ def add_dataproducts(taskID, dataproducts):
filename=dp['filename'], filename=dp['filename'],
name=dp['filename'], name=dp['filename'],
description=dp['filename'], description=dp['filename'],
quality=dp['quality'],
metadata=dp['metadata'],
task_type='dataproduct', task_type='dataproduct',
new_status=new_status, new_status=new_status,
parent=parent, parent=parent,
...@@ -150,4 +156,4 @@ def add_dataproducts(taskID, dataproducts): ...@@ -150,4 +156,4 @@ def add_dataproducts(taskID, dataproducts):
logger.info('addding dataproduct: '+str(myDataProduct)) logger.info('addding dataproduct: '+str(myDataProduct))
myDataProduct.save() myDataProduct.save()
return taskID
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
{% include 'taskdatabase/pagination.html' %} {% include 'taskdatabase/pagination.html' %}
</div> </div>
<p class="footer"> Version 1.0.0 (22 dec 2020 - 14:30) <p class="footer"> Version 1.0.0 (23 dec 2020 - 08:00)
<script type="text/javascript"> <script type="text/javascript">
(function(seconds) { (function(seconds) {
var refresh, var refresh,
......
...@@ -452,19 +452,15 @@ class PostDataproductsView(generics.CreateAPIView): ...@@ -452,19 +452,15 @@ class PostDataproductsView(generics.CreateAPIView):
pagination_class = DataProductsPagination pagination_class = DataProductsPagination
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
# read the arguments from the request
try:
taskID = self.request.query_params['taskID']
except:
taskID = None
try: try:
body_unicode = request.body.decode('utf-8') body_unicode = request.body.decode('utf-8')
dataproducts = json.loads(body_unicode) dataproducts = json.loads(body_unicode)
except: except Exception as e:
print(e)
dataproducts = None dataproducts = None
taskID = algorithms.add_dataproducts(taskID, dataproducts) taskID = algorithms.add_dataproducts(dataproducts)
# return a response # return a response
return Response({ return Response({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment