Skip to content

Instantly share code, notes, and snippets.

@ewancook
Last active December 15, 2020 11:54
Show Gist options
  • Save ewancook/b7f50fdaa4abb9c3864b14acf736aad8 to your computer and use it in GitHub Desktop.
Save ewancook/b7f50fdaa4abb9c3864b14acf736aad8 to your computer and use it in GitHub Desktop.
Command Line Conversion (Transcriber)
#!/usr/bin/env python3
import argparse
from multiprocessing import freeze_support
from transcriber.converter.dbfworker import utils
from transcriber.converter.dbfworker.worker import DBFWorker
from transcriber.dbf.parser import Parser
TAG_LABEL = "Tagname"
def retrieve_tags(tag_file):
parser = Parser(required_fields=[TAG_LABEL])
return [r[TAG_LABEL].decode().strip() for r in parser.parse_all(tag_file)]
def run(float_file, tag_file, precision, average_rows):
try:
tags = retrieve_tags(tag_file)
worker = DBFWorker(
tag_lookup=tags,
tags=set(tags),
decimal_places=precision,
filename=float_file,
rows_to_average=average_rows,
)
print(f"Successfully converted {worker.work()}")
except Exception as e:
print(f"Conversion failed ({e})")
if __name__ == "__main__":
freeze_support()
parser = argparse.ArgumentParser(
description="Convert FactoryTalk DAT Files"
)
parser.add_argument(
"-f", "--float-file", required=True, help="Float File [(Float).DAT]"
)
parser.add_argument(
"-t", "--tag-file", required=True, help="Tag File [(Tagname).DAT]"
)
parser.add_argument(
"-o", "--output-file", required=True, help="Output File"
)
parser.add_argument(
"-p", "--precision", help="Precision", default=8, type=int
)
parser.add_argument(
"-a", "--average-rows", help="Rows to Average", default=1, type=int
)
args = parser.parse_args()
utils.transcribed_filename = lambda x: args.output_file
average_rows = None if args.average_rows < 2 else args.average_rows
run(args.float_file, args.tag_file, args.precision, average_rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment