forked from TandonDevOps/IndraABM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_combiner.html
77 lines (73 loc) · 6.16 KB
/
json_combiner.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module json_combiner</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>json_combiner</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/gcallah/TandonDevOps/IndraABM/json_combiner.py">/home/gcallah/TandonDevOps/IndraABM/json_combiner.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="argparse.html">argparse</a><br>
</td><td width="25%" valign=top><a href="json.html">json</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-combine_models"><strong>combine_models</strong></a>(models, known_models=[])</dt><dd><tt>Merges known models (from models.json) with models from<br>
model.json files<br>
<br>
models.json could have models that don't have a model.json files<br>
<br>
<a href="#-combine_models">combine_models</a>() just puts every unique models into our set<br>
<br>
Note: this script's definition of unique is purely based on "source"<br>
field. The reason is that a model's source should not be the same<br>
as another model.<br>
<br>
This does mean that if a model's source is changed,<br>
a new model id is assigned.<br>
The old instance of the model will remain in models.json</tt></dd></dl>
<dl><dt><a name="-get_model_id"><strong>get_model_id</strong></a>(targetValue, known_models)</dt><dd><tt>Gets the model id for the model with given targetValue<br>
targetValue should be the source since its used as the unique feature<br>
of each model</tt></dd></dl>
<dl><dt><a name="-get_models"><strong>get_models</strong></a>(model_files)</dt><dd><tt>return all the models from list of model files (.json) for processing</tt></dd></dl>
<dl><dt><a name="-get_prev_models"><strong>get_prev_models</strong></a>(filepath)</dt><dd><tt>Reads from models.json, which also happens to be our DEST_FOLDER<br>
If our DEST_FOLDER doesn't exist, it will just create the new file<br>
Otherwise, it will read in the json,<br>
so the script knows the model ID for exisiting models</tt></dd></dl>
<dl><dt><a name="-has_model"><strong>has_model</strong></a>(targetValue, models)</dt><dd><tt>Checks if a model exists with given targetValue<br>
Model should have source_field</tt></dd></dl>
<dl><dt><a name="-init_model_id"><strong>init_model_id</strong></a>(known_models)</dt><dd><tt>Sets model_id to be the next avaliable or free id for use<br>
Its based on whether there are existing models that the script is aware<br>
of. (if models.json doesn't exist, then it assume no existing models<br>
were ever created)<br>
model_id will default to 0 if no known model id were used</tt></dd></dl>
<dl><dt><a name="-main"><strong>main</strong></a>()</dt></dl>
<dl><dt><a name="-print_result"><strong>print_result</strong></a>()</dt><dd><tt>Handy function to print result_json</tt></dd></dl>
<dl><dt><a name="-save_result"><strong>save_result</strong></a>(dest_fp)</dt><dd><tt>Handy function to encode result_json to json and save to file</tt></dd></dl>
<dl><dt><a name="-script_output"><strong>script_output</strong></a>(message, withName=True)</dt><dd><tt>Wrapper for print to include the script's name</tt></dd></dl>
<dl><dt><a name="-validate_config"><strong>validate_config</strong></a>()</dt><dd><tt>Checks the configuration of this script</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>DB_NAME</strong> = 'models_database'<br>
<strong>ID_FIELD</strong> = 'model ID'<br>
<strong>SOURCE_FIELD</strong> = 'source'<br>
<strong>model_id</strong> = 0<br>
<strong>result_json</strong> = {'models_database': []}<br>
<strong>script_name</strong> = '/usr/bin/pydoc3'</td></tr></table>
</body></html>