def setup_scd(dbname, number): open(os.path.expanduser(dbname), 'w') output_conn = sqlite3.connect(dbname) output_cur = output_conn.cursor() output_cur.execute("CREATE TABLE scd " "(key INTEGER PRIMARY KEY, attr1 INTEGER, " "attr2 INTEGER, version INTEGER)") output_conn.commit() output_wrapper = pygrametl.ConnectionWrapper(connection=output_conn) scd = SlowlyChangingDimension( name='scd', key='key', attributes=['attr1', 'attr2', 'version'], lookupatts=['attr2'], versionatt='version' ) data = [] total_elapsed = 0. print('Generating scd data') start = time.monotonic() for i in range(1, number + 1): data.append({'attr1': i, 'attr2': number + 1 - i}) end = time.monotonic() elapsed = end - start print('Generated: {}{}'.format(round(elapsed, 3), 's')) total_elapsed += elapsed print('Inserting data into scd') start = time.monotonic() for row in data: scd.scdensure(row) end = time.monotonic() elapsed = end - start print('Inserted: {}{}'.format(round(elapsed, 3), 's')) total_elapsed += elapsed print('DW populated') print('Total time: {}{}\n'.format(round(total_elapsed, 3), 's')) output_conn.commit()
cid_map = {} for row in country_src: cid = country_dim.ensure(row) cid_map[row["city"]] = cid # We populate the authordim and the fact table for row in author_src: if row["city"] in ["Hadsten", "Skanderborg", "Kobenhavn"]: row["cid"] = cid_map[row["city"]] else: row["cid"] = None row["name"] = row["firstname"] + " " + row["lastname"] row.pop("aid", 0) # Gets rid of aid so that pygrametl can generate them # Placing new row in author_dim row["aid"] = author_dim.ensure(row) # Placing new row in fact_table fact_table.ensure(row) # Places books directly into book_dim for row in book_src: book_dim.scdensure(row) wrapper.commit() wrapper.close() author_conn.close() book_conn.close() country_handle.close()