def handle(self, *args, **options):
job_uuid = options['job_uuid']
csv_filename = options['csv_file']
key_column = options['key_column']
skip_columns = options['skip_columns']
skip_columns = skip_columns.split(',') if skip_columns is not None else []
skip_columns.append('id')
try:
job = AnalysisJob.objects.get(pk=job_uuid)
except (AnalysisJob.DoesNotExist, ValueError, KeyError):
print('WARNING: Tried to update overall_scores for invalid job {} '
'from file {}'.format(job_uuid, csv_filename))
return
with open(csv_filename, 'r') as csv_file:
reader = csv.DictReader(csv_file)
results = {}
for row in reader:
key_column_value = row.pop(key_column)
metric = self.clean_metric_dict(row.copy(), skip_columns=skip_columns)
results[key_column_value] = metric
job.overall_scores = results
job.save()
self.stdout.write('{}: Loaded overall_scores from {}'.format(job, csv_filename))
load_overall_scores.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录