123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!usr/bin/env python
- # -*- coding: utf8 -*-
- import os
- import pandas as pd
- from ChildProject.projects import ChildProject
- def _correct_ages(path_dataset, path_metrics):
- project = ChildProject(path_dataset)
- project.read()
- project.recordings["age"] = project.compute_ages()
- updated_ages = project.recordings[["age", "session_id"]]
- updated_ages['age'] = updated_ages['age'].apply(int)
- metrics = pd.read_csv(path_metrics)
- for _, row in updated_ages.iterrows():
- old_age = metrics.loc[metrics['session_id']==row['session_id']]
- if not old_age.empty:
- metrics.loc[metrics['session_id']==row['session_id'], 'age'] = row['age']
- metrics.to_csv(path_metrics, index=False)
- def main(**kwargs):
- _correct_ages(**kwargs)
- def _parse_args(argv):
- import argparse
- parser = argparse.ArgumentParser(description='Correct ages in the metrics files.')
- parser.add_argument('--path-dataset', help='Path to the dataset.')
- parser.add_argument('--path-metrics', help='Path to the CSV metrics file.')
- args = parser.parse_args(argv)
- return vars(args)
- if __name__ == '__main__':
- import sys
- import logging
- pgrm_name, argv = sys.argv[0], sys.argv[1:]
- args = _parse_args(argv)
- try:
- main(**args)
- sys.exit(0)
- except Exception as e:
- logging.exception(e)
- sys.exit(1)
|