Exemplo n.º 1
0
def func_gen_ex(args):
    p1=argparse.ArgumentParser(prog='gen-ex')
    p1.add_argument('-u', dest='username', help='Input dataset owner')
    p1args=p1.parse_args(args)
    try:
        if p1args.username:
            username=p1args.username
        else:
            username=raw_input('Username: '******'User does not exist',username))
            return
        else:
            with transaction.atomic():
                inputdata=InputData.objects.create(user=user)
                logging.info(sjoin('Generating example data for',username))
                import datagen
                scale=(2E3, 2.4E3)
                hpath='proj4001/inputs/%s'%inputdata.serial
                datagen.main(scale, 'hdfs:'+hpath)
                inputdata.save()
            try:
                InputData.objects.get(serial=inputdata.serial)
                if FORMAT==F_TEXT:
                    print 'OK', inputdata.serial
                elif FORMAT==F_JSON:
                    print ok({'serial': inputdata.serial, 'exp_date': inputdata.exp_date.strftime("%D")})
            except InputData.DoesNotExist:
                print_err('I/O Error')
                return
    except KeyboardInterrupt:
        print_err('Interrupted')
        return
Exemplo n.º 2
0
def _run_main(tmpdir, schema, args):
    test_tmpdir = tmpdir.mkdir("testdata")
    schemafile = test_tmpdir.join("schema.txt")
    schemafile.write(schema)
    outfile = test_tmpdir.join("result.txt")
    args += ['-s', schemafile.strpath, outfile.strpath]
    main(args)
    with open(outfile.strpath) as outfile_obj:
        result = outfile_obj.read()
    return result
Exemplo n.º 3
0
def func_gen_ex(args):
    p1 = argparse.ArgumentParser(prog='gen-ex')
    p1.add_argument('-u', dest='username', help='Input dataset owner')
    p1args = p1.parse_args(args)
    try:
        if p1args.username:
            username = p1args.username
        else:
            username = raw_input('Username: '******'User does not exist', username))
            return
        else:
            with transaction.atomic():
                inputdata = InputData.objects.create(user=user)
                logging.info(sjoin('Generating example data for', username))
                import datagen
                scale = (2E3, 2.4E3)
                hpath = 'proj4001/inputs/%s' % inputdata.serial
                datagen.main(scale, 'hdfs:' + hpath)
                inputdata.save()
            try:
                InputData.objects.get(serial=inputdata.serial)
                if FORMAT == F_TEXT:
                    print 'OK', inputdata.serial
                elif FORMAT == F_JSON:
                    print ok({
                        'serial': inputdata.serial,
                        'exp_date': inputdata.exp_date.strftime("%D")
                    })
            except InputData.DoesNotExist:
                print_err('I/O Error')
                return
    except KeyboardInterrupt:
        print_err('Interrupted')
        return
Exemplo n.º 4
0
def test_demands_required_arguments():
    with raises(SystemExit):
        main([])
Exemplo n.º 5
0
 def test_args(self):
     datagen.main([
         '--config-file', './resources/data_schema.json', '--output-file',
         './resources/output.csv', '--record-count', '10'
     ])
Exemplo n.º 6
0
from random import uniform
from datagen.types import register_type, type_arg
from datagen import main


@type_arg("price")  # Use the same name as the type defined in reg_type()
def price_argument(
        arg):  # This method is passed the contents of what's in price[]
    return int(arg)  # This will get passed to price() when iterating


@register_type("price")  # the decorator sets the name of the type
def price(max_price):  # the method must accept one argument (even if not used)
    return round(uniform(0, max_price), 2)


if __name__ == '__main__':
    main()
Exemplo n.º 7
0
from random import uniform
from datagen.types import register_type, type_arg
from datagen import main


@type_arg("price")  # Use the same name as the type defined in reg_type()
def price_argument(arg):  # This method is passed the contents of what's in price[]
    return int(arg)  # This will get passed to price() when iterating


@register_type("price")
def price(arg):
    return round(uniform(0, 100), 2)


if __name__ == '__main__':
    main()
Exemplo n.º 8
0
 def __populate_table__(self):
     if self.current_create_table_stmt is not None:
         self.buffered_statements.extend(
             datagen.main(
                 self.current_create_table_stmt,
                 self.num_inserts).split('\n'))  # populate previous table