Exemplo n.º 1
0
    def convert(
        self,
        input_file,
        output_dir=None,
        output_format='json',
        export_with_errors=False,
        errors_file='./files/output/errors.json'
    ):

        #  Register custom importers
        c_importers = {
            'json': json_importer
        }

         #  Register custom exporters
        c_exporters = {
            'csv': csv_exporter
        }

        importer = Importer(custom_importers=c_importers)
        validator = HotelValidator()
        exporter = Exporter(custom_exporters=c_exporters)

        try:
            data =  importer.load(input_file)
            data, data_backup = tee(data)

            # Validate data
            for row in data:
                validator.validate(row)

            error_count = len(validator.errors)
            LOG.warning(f'Validated {validator.count} records. Found {error_count} errors.')
            if error_count:
                with open(errors_file, 'w') as error_file:
                    error_file.write(json.dumps(validator.errors))
                if export_with_errors:
                   LOG.debug(f'Export to {output_format} started.')
                   output = exporter.write(data_backup, output_dir, output_format)
                   LOG.warning(f'Exported successfully. View file: {os.path.abspath(output)}')
                else:
                    LOG.error(f'Errors identified. Export process stopped. You can view the error logs at {os.path.abspath(errors_file)}')
        except Exception as e:
            LOG.error(str(e))
Exemplo n.º 2
0
    o2 = str(o2[0])
    if bp != 'NA': bpcount += 1
    if ge != 'NA': gecount += 1
    if ag != 'NA': agcount += 1
    if tp != 'NA': tpcount += 1
    if pu != 'NA': pucount += 1
    if br != 'NA': brcount += 1
    if we != 'NA': wecount += 1
    if he != 'NA': hecount += 1
    if bm != 'NA': bmcount += 1
    if o2 != 'NA': o2count += 1
    exp.addToTable(numb=str(i),  gender=ge, age=ag, bodyTemp=tp, pulse=pu, breath=br, weight=we, height=he, bmi=bm,
                   bloodP=bp, o2sat=o2, o2cond=o2_cond)
    i += 1

exp.write()

print('=======================================================================================================================')
print('Hits : (percentage of transcripts where the information has been found)')
print('gender\t\t\t:',              round(gecount/i, 2)*100, '%')
print('age\t\t\t:',                 round(agcount/i, 2)*100, '%')
print('weight\t\t\t:',              round(wecount/i, 2)*100, '%')
print('height\t\t\t:',              round(hecount/i, 2)*100, '%')
print('bmi\t\t\t:',                 round(bmcount/i, 2)*100, '%')
print('body temperature\t:',        round(tpcount/i, 2)*100, '%')
print('pulse\t\t\t:',               round(pucount/i, 2)*100, '%')
print('breathing frequency\t:',     round(brcount/i, 2)*100, '%')
print('blood pressure\t\t:',        round(bpcount/i, 2)*100, '%')
print('oxygen saturation\t\t:',     round(o2count/i, 2)*100, '%')
print('=======================================================================================================================')