#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#
#     Authors:
#       Joan Sala Calero (joan.sala@bsc.es)

import glob
import json

def write_products(tag, outfile):
    # Read all datasets
    all_datasets = []
    for f in glob.glob('./conf/*{}*json'.format(tag)):
        with open(f, 'r') as fp:
            prods = json.load(fp)
            for p in prods:
                p['sample'] = 'yes'
                all_datasets.append(p)

    # Write all products in one file (with sample)
    with open(outfile, 'w') as fw:
        json.dump(all_datasets, fw, indent=4)

# Separate files, separate download scripts
write_products('daily', './conf/all_d.json')
write_products('monthly', './conf/all_m.json')