jsongrapher 1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- JSONGrapher/JSONRecordCreator.py +894 -0
- JSONGrapher/__init__.py +3 -0
- JSONGrapher/units_list.py +450 -0
- jsongrapher-1.6.data/data/LICENSE +24 -0
- jsongrapher-1.6.data/data/README.md +79 -0
- jsongrapher-1.6.dist-info/LICENSE +24 -0
- jsongrapher-1.6.dist-info/METADATA +101 -0
- jsongrapher-1.6.dist-info/RECORD +10 -0
- jsongrapher-1.6.dist-info/WHEEL +5 -0
- jsongrapher-1.6.dist-info/top_level.txt +1 -0
JSONGrapher/__init__.py
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
#Try to do things a bit like https://github.com/python/cpython/blob/master/Lib/collections/__init__.py
|
2
|
+
#Except instead of putting things here directly in __init__, we'll import them so they are accessible by importing the module.
|
3
|
+
from JSONGrapherRC.JSONRecordCreator import *
|
@@ -0,0 +1,450 @@
|
|
1
|
+
|
2
|
+
'''
|
3
|
+
#This units list came from the UUC units list. https://github.com/Lemonexe/UUC/blob/master/app/data.js
|
4
|
+
# it has been converted to python and contains all of the program constants, the unit database, and database of prefixes
|
5
|
+
# 'en' is for English, 'cz' is for Czech, and "ae" is for American English.
|
6
|
+
|
7
|
+
metre → meter
|
8
|
+
mole → mol (sometimes abbreviated in scientific contexts)
|
9
|
+
dioptre → diopter
|
10
|
+
normal cubic metre → normal cubic meter
|
11
|
+
normal litre → normal liter
|
12
|
+
milimetre of mercury → millimeter of mercury
|
13
|
+
litre → liter
|
14
|
+
tonne → metric ton (often written as ton in American English)
|
15
|
+
cubic centimetre → cubic centimeter
|
16
|
+
|
17
|
+
'''
|
18
|
+
import math as Math
|
19
|
+
#program constants
|
20
|
+
dict_csts = {
|
21
|
+
"R": 8.3144598, # [J/K/mol]
|
22
|
+
"TC0": 273.15, # [K]
|
23
|
+
"TF0": 459.67 * 5 / 9, # [K]
|
24
|
+
"atm": 101325, # [Pa]
|
25
|
+
"mile": 1609.344, # [m]
|
26
|
+
"bbl": 158.987294928e-3, # [m3]
|
27
|
+
"q": 1.6021766208e-19, # [C]
|
28
|
+
"BTU": 1055.05585, # [J]
|
29
|
+
"APIk": 141.5e3, # [1]
|
30
|
+
"APIq": -131.5, # [m3/kg]
|
31
|
+
"dTnote": {"cz": "Viz °C pro důležitou poznámku.", "en": "See °C for an important note."},
|
32
|
+
"Hgnote": {"cz": "Mezi mmHg a Torr je nepatrný rozdíl.", "en": "There is a negligible difference between mmHg and Torr."}
|
33
|
+
}
|
34
|
+
|
35
|
+
#Class to access the above dictionary objects with notation like javascript.
|
36
|
+
class Csts:
|
37
|
+
def __init__(self, constants):
|
38
|
+
self.__dict__.update(constants)
|
39
|
+
|
40
|
+
# Create an instance of Csts
|
41
|
+
csts = Csts(dict_csts)
|
42
|
+
|
43
|
+
|
44
|
+
'''
|
45
|
+
Units object is the database of all known units.
|
46
|
+
v: [m,kg,s,A,K,mol,cd,$] represents the vector of powers of basic units, for example N=kg*m/s^2, therefore v = [1,1,-2,0,0,0,0]
|
47
|
+
id: string something unique. You can use the UnitConflicts() global function to detect possible id conflicts
|
48
|
+
alias: array array of strings - other ids that reference the unitprefix:
|
49
|
+
name: object defines full name or even a short description for every language mutation
|
50
|
+
k: number this coeficient equates value of the unit in basic units. For example minute = 60 seconds, therefore min.k = 60
|
51
|
+
"SI": True/false self-explanatory. This attribute doesn't really do anything, it's merely informational. Perhaps it's redundant, since all SI derived units have k = 1
|
52
|
+
basic: True/false whether it's basic SI unit or derived SI. Basic SI units are of utmost importance to the code, don't ever change them!
|
53
|
+
prefix: all/+/-/undefined it means: all prefixes allowed / only bigger than one allowed / lesser than one / prefixes disallowed. It's not really a restriction, just a recommendation.
|
54
|
+
"constant": True/undefined whether it is a constant. If true, attributes SI, basic and prefix are ignored. Prefix is disallowed.
|
55
|
+
"note": a note that conveys anything important beyond description - what is noteworthy or weird about this unit or its usage. Implemented as an object of strings for all language mutations.
|
56
|
+
'''
|
57
|
+
|
58
|
+
units_dict_list = [
|
59
|
+
# Eight basic units
|
60
|
+
{"v": [1, 0, 0, 0, 0, 0, 0, 0], "id": "m", "name": {"cz": "metr", "en": "metre", "ae": "meter"}, "k": 1, "SI": True, "basic": True, "prefix": "all"},
|
61
|
+
{"v": [0, 1, 0, 0, 0, 0, 0, 0], "id": "kg", "name": {"cz": "kilogram", "en": "kilogram"}, "k": 1, "SI": True, "basic": True, "note": {
|
62
|
+
"cz": "To protože kilogram se obtížně programuje, neboť samo 'kilo' je předpona. Proto jsem definoval také gram jako odvozenou jednotku SI, která může mít jakékoliv předpony.",
|
63
|
+
"en": "That's because kilogram is problematic to code, since the 'kilo' itself is a prefix. Therefore I have also defined gram as a derived SI unit, which can have all prefixes."
|
64
|
+
}},
|
65
|
+
{"v": [0, 0, 1, 0, 0, 0, 0, 0], "id": "s", "name": {"cz": "sekunda", "en": "second"}, "k": 1, "SI": True, "basic": True, "prefix": "-"},
|
66
|
+
{"v": [0, 0, 0, 1, 0, 0, 0, 0], "id": "A", "name": {"cz": "ampér", "en": "ampere"}, "k": 1, "SI": True, "basic": True, "prefix": "all"},
|
67
|
+
{"v": [0, 0, 0, 0, 1, 0, 0, 0], "id": "K", "name": {"cz": "kelvin", "en": "kelvin"}, "k": 1, "SI": True, "basic": True, "prefix": "all"},
|
68
|
+
{"v": [0, 0, 0, 0, 0, 1, 0, 0], "id": "mol", "name": {"cz": "mol", "en": "mole"}, "k": 1, "SI": True, "basic": True, "prefix": "all"},
|
69
|
+
{"v": [0, 0, 0, 0, 0, 0, 1, 0], "id": "cd", "name": {"cz": "kandela", "en": "candela"}, "k": 1, "SI": True, "basic": True, "prefix": "all"},
|
70
|
+
# USD arbitrarily set as basic unit. Reference to this unit is hardcoded in currency loading!
|
71
|
+
{"v": [0, 0, 0, 0, 0, 0, 0, 1], "id": "USD", "alias": ["$", "usd"], "name": {"cz": "americký dolar", "en": "US dollar"}, "k": 1, "basic": True, "prefix": "+"},
|
72
|
+
|
73
|
+
|
74
|
+
#ALL OTHER UNITS as {id: 'identifier',v: [0,0,0,0,0,0,0], "name": {"cz": 'CZ', "en": 'EN'}, "k":1, "SI": True, "prefix": 'all'},
|
75
|
+
#SI derived
|
76
|
+
{"v": [0,0,0,0,0,0,0,0], "id": '%', "name": {"cz": 'procento', "en": 'percent'}, "k":1e-2},
|
77
|
+
{"v": [0,0,0,0,0,0,0,0], "id": 'ppm', "name": {"cz": 'dílů na jeden milion', "en": 'parts per million'}, "k":1e-6},
|
78
|
+
{"v": [0,0,0,0,0,0,0,0], "id": 'ppb', "name": {"cz": 'dílů na jednu miliardu', "en": 'parts per billion'}, "k":1e-9},
|
79
|
+
{"v": [0,0,0,0,0,0,0,0], "id": 'rad', "name": {"cz": 'radián', "en": 'radian'}, "k":1, "SI": True, "prefix": '-', "note": {
|
80
|
+
"cz": 'Úhel považuji za bezrozměrné číslo, čili radián je identický s číslem 1.',
|
81
|
+
"en": 'I consider angle units to be dimensionless, with radian being identical to number 1.'}},
|
82
|
+
{"v": [0,0,0,0,0,0,0,0], "id": '°', "alias":['deg'], "name": {"cz": 'stupeň', "en": 'degree'}, "k":Math.pi/180},
|
83
|
+
{"v": [0,0,0,0,0,0,0,0], "id": 'gon', "name": {"cz": 'gradián', "en": 'gradian'}, "k":Math.pi/200},
|
84
|
+
{"v": [0,0,-1,0,0,0,0,0], "id": 'Hz', "name": {"cz": 'hertz', "en": 'hertz'}, "k":1, "SI": True, "prefix": 'all'},
|
85
|
+
{"v": [1,1,-2,0,0,0,0,0], "id": 'N', "name": {"cz": 'newton', "en": 'newton'}, "k":1, "SI": True, "prefix": 'all'},
|
86
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'Pa', "name": {"cz": 'pascal', "en": 'pascal'}, "k":1, "SI": True, "prefix": 'all'},
|
87
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'J', "name": {"cz": 'joule', "en": 'joule'}, "k":1, "SI": True, "prefix": 'all'},
|
88
|
+
{"v": [2,1,-3,0,0,0,0,0], "id": 'W', "name": {"cz": 'watt', "en": 'watt'}, "k":1, "SI": True, "prefix": 'all'},
|
89
|
+
{"v": [0,0,1,1,0,0,0,0], "id": 'C', "name": {"cz": 'coulomb', "en": 'coulomb'}, "k":1, "SI": True, "prefix": 'all'},
|
90
|
+
{"v": [2,1,-3,-1,0,0,0,0], "id": 'V', "name": {"cz": 'volt', "en": 'volt'}, "k":1, "SI": True, "prefix": 'all'},
|
91
|
+
{"v": [-2,-1,4,2,0,0,0,0], "id": 'F', "name": {"cz": 'farad', "en": 'farad'}, "k":1, "SI": True, "prefix": 'all'},
|
92
|
+
{"v": [2,1,-3,-2,0,0,0,0], "id": 'ohm', "name": {"cz": 'ohm', "en": 'ohm'}, "k":1, "SI": True, "prefix": 'all'},
|
93
|
+
{"v": [-2,-1,3,2,0,0,0,0], "id": 'S', "name": {"cz": 'siemens', "en": 'siemens'}, "k":1, "SI": True, "prefix": 'all'},
|
94
|
+
{"v": [2,1,-2,-1,0,0,0,0], "id": 'Wb', "name": {"cz": 'weber', "en": 'weber'}, "k":1, "SI": True, "prefix": 'all'},
|
95
|
+
{"v": [0,1,-2,-1,0,0,0,0], "id": 'T', "name": {"cz": 'tesla', "en": 'tesla'}, "k":1, "SI": True, "prefix": 'all'},
|
96
|
+
{"v": [2,1,-2,-2,0,0,0,0], "id": 'H', "name": {"cz": 'henry', "en": 'henry'}, "k":1, "SI": True, "prefix": 'all'},
|
97
|
+
{"v": [0,0,0,0,1,0,0,0], "id": '°C', "name": {"cz": 'stupeň Celsia', "en": 'degree Celsius'}, "k":1, "SI": True, "note": {
|
98
|
+
"cz": '°C je považován za jednotku rozdílu teploty (ΔT). Absolutní teplota (T) je zapsána pomocí složených závorek, např. {10°C}, viz tutoriál',
|
99
|
+
"en": '°C is considered to be a unit of temperature difference (ΔT). Absolute temperature (T) is written using curly braces, e.g. {10°C}, see tutorial'}},
|
100
|
+
|
101
|
+
{"v": [0,0,0,0,0,0,1,0], "id": 'lm', "name": {"cz": 'lumen', "en": 'lumen'}, "k":1, "SI": True, "prefix": 'all'},
|
102
|
+
{"v": [-2,0,0,0,0,0,1,0], "id": 'lx', "name": {"cz": 'lux', "en": 'lux'}, "k":1, "SI": True, "prefix": 'all'},
|
103
|
+
{"v": [0,0,-1,0,0,0,0,0], "id": 'Bq', "name": {"cz": 'becquerel', "en": 'becquerel'}, "k":1, "SI": True, "prefix": 'all'},
|
104
|
+
{"v": [0,0,-1,0,0,0,0,0], "id": 'Rd', "name": {"cz": 'rutherford', "en": 'rutherford'}, "k":1e6, "SI": True, "prefix": 'all'},
|
105
|
+
{"v": [2,0,-2,0,0,0,0,0], "id": 'Gy', "name": {"cz": 'gray', "en": 'gray'}, "k":1, "SI": True, "prefix": 'all'},
|
106
|
+
{"v": [2,0,-2,0,0,0,0,0], "id": 'Sv', "name": {"cz": 'sievert', "en": 'sievert'}, "k":1, "SI": True, "prefix": 'all'},
|
107
|
+
{"v": [-1,0,0,0,0,0,0,0], "id": 'dpt', "name": {"cz": 'dioptrie', "en": 'dioptre', "ae":'diopter'}, "k":1, "SI": True},
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
#non-SI
|
112
|
+
{"v": [0,0,0,0,0,1,0,0], "id": 'Nm3', "alias":['Ncm'], "name": {"cz": 'normální krychlový metr', "en": 'normal cubic metre'}, "k":csts.atm/csts.TC0/csts.R, "note": {
|
113
|
+
"cz": 'Definován při 0°C a 1 atm. Navzdory názvu je Nm3 jednotkou látkového množství, nikoliv objemu.',
|
114
|
+
"en": 'Defined at 0°C and 1 atm. Despite the name, Nm3 is actually amount of substance, not volume.'}},
|
115
|
+
{"v": [0,0,0,0,0,1,0,0], "id": 'Ndm3', "alias":['Nl'], "name": {"cz": 'normální litr', "en": 'normal litre', 'ae':"normal liter"}, "k":csts.atm/csts.TC0/csts.R/1000, "note": {"cz": 'Viz Nm3 pro vysvětlení.', "en": 'See Nm3 for explanation.'}},
|
116
|
+
{"v": [0,0,0,0,0,1,0,0], "id": 'SCF', "name": {"cz": 'normální krychlová stopa', "en": 'standard cubic foot'}, "k":0.028317*csts.atm/288.7/csts.R, "note": {"cz": 'Viz Nm3 pro vysvětlení.', "en": 'See Nm3 for explanation.'}},
|
117
|
+
|
118
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'min', "name": {"cz": 'minuta', "en": 'minute'}, "k":60},
|
119
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'h', "name": {"cz": 'hodina', "en": 'hour'}, "k":3600},
|
120
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'd', "alias":['day'], "name": {"cz": 'den', "en": 'day'}, "k":3600*24},
|
121
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'week', "name": {"cz": 'týden', "en": 'week'}, "k":3600*24*7},
|
122
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'ftn', "name": {"cz": 'dva týdny', "en": 'fortnight'}, "k":1209600, "prefix": 'all'},
|
123
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'month', "alias":['mth', 'měs'], "name": {"cz": 'průměrný měsíc', "en": 'average month'}, "k":3600*24*30.436875, "note": {
|
124
|
+
"cz": 'Vypočten z gregoriánského roku.',
|
125
|
+
"en": 'Calculated from gregorian year.'}},
|
126
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'yr', "alias":['year'], "name": {"cz": 'gregoriánský rok', "en": 'gregorian year'}, "k":3600*24*365.2425, "note": {
|
127
|
+
"cz": 'Pokud si nejste jisti, který rok použít, zvolte tento. Juliánský rok je zastaralý.',
|
128
|
+
"en": 'If you are unsure which year to use, pick this one. Julian year is obsolete.'}},
|
129
|
+
{"v": [0,0,1,0,0,0,0,0], "id": 'jyr', "name": {"cz": 'juliánský rok', "en": 'julian year'}, "k":3600*24*365.25},
|
130
|
+
|
131
|
+
{"v": [0,0,-1,0,0,0,0,0], "id": 'rpm', "name": {"cz": 'otáčky za minutu', "en": 'revolutions per minute'}, "k":1/60},
|
132
|
+
|
133
|
+
{"v": [0,0,0,0,1,0,0,0], "id": '°F', "name": {"cz": 'stupeň Fahrenheita', "en": 'degree Fahrenheit'}, "k":5/9, "note": csts.dTnote},
|
134
|
+
{"v": [0,0,0,0,1,0,0,0], "id": '°Re', "alias":['°Ré', '°r'], "name": {"cz": 'stupeň Réaumura', "en": 'degree Réaumur'}, "k":1.25, "note": csts.dTnote},
|
135
|
+
{"v": [0,0,0,0,1,0,0,0], "id": '°R', "name": {"cz": 'Rankine', "en": 'Rankine'}, "k":5/9, "note": csts.dTnote},
|
136
|
+
|
137
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'Å', "name": {"cz": 'angstrom', "en": 'angstrom'}, "k":1e-10, "SI": True},
|
138
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'th', "name": {"cz": 'thou', "en": 'thou'}, "k":2.54e-5},
|
139
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'in', "name": {"cz": 'palec', "en": 'inch'}, "k":2.54e-2},
|
140
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'ft', "name": {"cz": 'stopa', "en": 'foot'}, "k":0.3048, "prefix": '+'},
|
141
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'yd', "name": {"cz": 'yard', "en": 'yard'}, "k":0.9144},
|
142
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'fur', "name": {"cz": 'furlong', "en": 'furlong'}, "k":201.168, "prefix": 'all'},
|
143
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'mi', "name": {"cz": 'míle', "en": 'mile'}, "k":csts.mile},
|
144
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'nmi', "name": {"cz": 'námořní míle', "en": 'nautical mile'}, "k":1852},
|
145
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'au', "name": {"cz": 'astronomická jednotka', "en": 'astronomical unit'}, "k":149597870700, "prefix": '+'},
|
146
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'pc', "name": {"cz": 'parsek', "en": 'parsec'}, "k":3.08567758149137e16, "prefix": '+'},
|
147
|
+
{"v": [1,0,0,0,0,0,0,0], "id": 'ly', "name": {"cz": 'světelný rok', "en": 'light-year'}, "k":9460730472580800, "prefix": '+'},
|
148
|
+
|
149
|
+
{"v": [2,0,0,0,0,0,0,0], "id": 'a', "name": {"cz": 'ar', "en": 'ar'}, "k":100, "SI": True, "prefix": '+'},
|
150
|
+
{"v": [2,0,0,0,0,0,0,0], "id": 'ac', "name": {"cz": 'akr', "en": 'acre'}, "k":4046.872},
|
151
|
+
{"v": [2,0,0,0,0,0,0,0], "id": 'darcy', "name": {"cz": 'darcy', "en": 'darcy'}, "k": 9.869233e-13},
|
152
|
+
|
153
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'l', "name": {"cz": 'litr', "en": 'litre', "ae":'liter'}, "k":1e-3, "SI": True, "prefix": 'all'},
|
154
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'pt', "name": {"cz": 'pinta', "en": 'pint'}, "k":568.261e-6},
|
155
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'gal', "name": {"cz": 'americký galon', "en": 'US gallon'}, "k":3.785412e-3},
|
156
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'bsh', "name": {"cz": 'americký bušl', "en": 'US bushel'}, "k":35.2391e-3},
|
157
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'ccm', "name": {"cz": 'kubický centimetr', "en": 'cubic centimetr', "ae": 'cubic centimeter'}, "k":1e-6},
|
158
|
+
{"v": [3,0,0,0,0,0,0,0], "id": 'bbl', "name": {"cz": 'barel ropy', "en": 'oil barrel'}, "k":csts.bbl, "prefix": '+'},
|
159
|
+
|
160
|
+
{"v": [3,0,-1,0,0,0,0,0], "id": 'BPD', "name": {"cz": 'barel ropy za den', "en": 'oil barrel per day'}, "k":csts.bbl/3600/24, "prefix": '+'},
|
161
|
+
|
162
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'g', "name": {"cz": 'gram', "en": 'gram'}, "k":1e-3, "SI": True, "prefix": 'all'},
|
163
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 't', "name": {"cz": 'tuna', "en": 'tonne', "ae":'metric ton'}, "k":1000, "SI": True, "prefix": '+'},
|
164
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'gr', "name": {"cz": 'grain', "en": 'grain'}, "k":64.79891e-6},
|
165
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'oz', "name": {"cz": 'once', "en": 'ounce'}, "k":28.349523e-3},
|
166
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'ozt', "name": {"cz": 'trojská unce', "en": 'troy ounce'}, "k":31.1034768e-3},
|
167
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'ct', "name": {"cz": 'karát', "en": 'carat'}, "k":200e-6},
|
168
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'lb', "alias":['lbs'], "name": {"cz": 'libra', "en": 'pound'}, "k":0.45359237},
|
169
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'st', "name": {"cz": 'kámen', "en": 'stone'}, "k":6.35029318},
|
170
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'slug', "name": {"cz": 'slug', "en": 'slug'}, "k":14.593903},
|
171
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'fir', "name": {"cz": 'firkin', "en": 'firkin'}, "k":40.8233133, "prefix": 'all'},
|
172
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'ts', "name": {"cz": 'krátká tuna', "en": 'short ton'}, "k":907.18474},
|
173
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'tl', "name": {"cz": 'imperiální tuna', "en": 'long ton'}, "k":1016},
|
174
|
+
{"v": [0,1,0,0,0,0,0,0], "id": 'u', "alias":['Da'], "name": {"cz": 'dalton (atomová hmotnostní konstanta)', "en": 'dalton (unified atomic mass unit)'}, "k":1.660539040e-27},
|
175
|
+
|
176
|
+
{"v": [1,0,-1,0,0,0,0,0], "id": 'mph', "name": {"cz": 'míle za hodinu', "en": 'mile per hour'}, "k":csts.mile/3600},
|
177
|
+
{"v": [1,0,-1,0,0,0,0,0], "id": 'kn', "name": {"cz": 'uzel', "en": 'knot'}, "k":1852/3600},
|
178
|
+
|
179
|
+
{"v": [1,1,-2,0,0,0,0,0], "id": 'dyn', "name": {"cz": 'dyn', "en": 'dyne'}, "k":1e-5, "prefix": 'all'},
|
180
|
+
|
181
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'Wh', "name": {"cz": 'watthodina', "en": 'watt-hour'}, "k":3600, "prefix": 'all'},
|
182
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'eV', "name": {"cz": 'elektronvolt', "en": 'electronvolt'}, "k":csts.q, "prefix": 'all'},
|
183
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'erg', "name": {"cz": 'erg', "en": 'erg'}, "k":1e-7, "SI": True, "prefix": 'all'},
|
184
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'Btu', "alias":['BTU','btu'], "name": {"cz": 'britská tepelná jednotka', "en": 'british thermal unit'}, "k":csts.BTU, "prefix": 'all'},
|
185
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'Chu', "alias":['CHU','chu'], "name": {"cz": 'celsiova jednotka tepla', "en": 'celsius heat unit'}, "k": 1.899101e3, "prefix": 'all'},
|
186
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'thm', "name": {"cz": 'therm', "en": 'therm'}, "k":csts.BTU*1e5, "prefix": 'all'},
|
187
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'cal', "name": {"cz": 'kalorie', "en": 'calorie'}, "k":4.184, "prefix": 'all'},
|
188
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'TNT', "name": {"cz": 'ekvivalent tuny TNT', "en": 'ton of TNT equivalent'}, "k":4.184e9, "prefix": '+'},
|
189
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'BOE', "alias": ['BFOE'], "name": {"cz": 'ekvivalent barelu ropy', "en": 'barrel of oil equivalent'}, "k":5.8e6*csts.BTU, "prefix": '+'},
|
190
|
+
{"v": [2,1,-2,0,0,0,0,0], "id": 'GGE', "name": {"cz": 'ekvivalent galonu benzínu', "en": 'gasoline gallon equivalent'}, "k":114e3*csts.BTU, "prefix": '+'},
|
191
|
+
|
192
|
+
{"v": [-1,0,0,1,0,0,0,0], "id": 'Oe', "name": {"cz": 'oersted', "en": 'oersted'}, "k":1000/(4*Math.pi), "prefix": 'all'},
|
193
|
+
|
194
|
+
{"v": [2,1,-3,0,0,0,0,0], "id": 'hp', "name": {"cz": 'imperiální koňská síla', "en": 'imperial horsepower'}, "k":745.69987158227022},
|
195
|
+
|
196
|
+
{"v": [-1,1,-1,0,0,0,0,0], "id": 'P', "name": {"cz": 'poise', "en": 'poise'}, "k":0.1, "SI": True, "prefix": 'all'},
|
197
|
+
{"v": [2,0,-1,0,0,0,0,0], "id": 'St', "name": {"cz": 'stokes', "en": 'stokes'}, "k":1e-4, "SI": True, "prefix": 'all'},
|
198
|
+
|
199
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'bar', "name": {"cz": 'bar', "en": 'bar'}, "k":1e5, "SI": True, "prefix": 'all'},
|
200
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'atm', "name": {"cz": 'atmosféra', "en": 'atmosphere'}, "k":csts.atm, "note": {
|
201
|
+
"cz": 'Také slouží jako standardní tlak.',
|
202
|
+
"en": 'Also serves as standard pressure.'}},
|
203
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'mmHg', "name": {"cz": 'milimetr rtuťového sloupce', "en": 'millimetre of mercury', "ae": 'millimeter of mercury'}, "k":133.322387415, "note": csts.Hgnote},
|
204
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'Torr', "alias":['torr'], "name": {"cz": 'torr', "en": 'torr'}, "k":csts.atm/760, "prefix": 'all', "note": csts.Hgnote},
|
205
|
+
{"v": [-1,1,-2,0,0,0,0,0], "id": 'psi', "name": {"cz": 'libra na čtvereční palec', "en": 'pound per square inch'}, "k":6894.757293168362, "prefix": 'all'},
|
206
|
+
|
207
|
+
{"v": [0,1,-2,-1,0,0,0,0], "id": 'G', "name": {"cz": 'gauss', "en": 'gauss'}, "k":0.0001, "SI": True, "prefix": 'all'},
|
208
|
+
|
209
|
+
{"v": [0,0,-1,0,0,0,0,0], "id": 'Ci', "name": {"cz": 'Curie', "en": 'Curie'}, "k":3.7e10, "SI": False, "prefix": 'all'},
|
210
|
+
{"v": [0,-1,1,1,0,0,0,0], "id": 'R', "name": {"cz": 'Rentgen', "en": 'Roentgen'}, "k":2.58e-4, "SI": False, "prefix": 'all'},
|
211
|
+
{"v": [0,0,0,0,0,0,0,0], "id": 'monolayer', "alias":['monolayers'], "name": {"cz": 'monolayer', "en": 'monolayer'}, "k":1},
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
#constants
|
216
|
+
{"v": [1,0,-2,0,0,0,0,0], "id": '_g', "name": {"cz": 'normální tíhové zrychlení', "en": 'standard gravity'}, "k":9.80665, "constant": True, "note": {
|
217
|
+
"cz": 'Nikoliv univerzální konstanta, nýbrž konvenční.',
|
218
|
+
"en": 'Not a universal constant, but a conventional one.'}},
|
219
|
+
{"v": [1,0,-1,0,0,0,0,0], "id": '_c', "name": {"cz": 'rychlost světla ve vakuu', "en": 'speed of light in vacuum'}, "k":299792458, "constant": True},
|
220
|
+
{"v": [3,-1,-2,0,0,0,0,0], "id": '_G', "name": {"cz": 'gravitační konstanta', "en": 'gravitational constant'}, "k":6.67408e-11, "constant": True},
|
221
|
+
{"v": [2,1,-1,0,0,0,0,0], "id": '_h', "name": {"cz": 'Planckova konstanta', "en": 'Planck constant'}, "k":6.626070040e-34, "constant": True},
|
222
|
+
{"v": [2,1,-2,0,-1,0,0,0], "id": '_k', "name": {"cz": 'Boltzmannova konstanta', "en": 'Boltzmann constant'}, "k":1.38064852e-23, "constant": True},
|
223
|
+
{"v": [2,1,-2,0,-1,-1,0,0], "id": '_R', "name": {"cz": 'plynová konstanta', "en": 'gas constant'}, "k":csts.R, "constant": True},
|
224
|
+
{"v": [1,1,-2,-2,0,0,0,0], "id": '_mu', "alias":['μ'], "name": {"cz": 'permeabilita vakua', "en": 'vacuum permeability'}, "k":1.2566370614e-6, "constant": True},
|
225
|
+
{"v": [-3,-1,4,2,0,0,0,0], "id": '_E', "name": {"cz": 'permitivita vakua', "en": 'vacuum permittivity'}, "k":8.854187817e-12, "constant": True},
|
226
|
+
{"v": [0,0,1,1,0,0,0,0], "id": '_q', "name": {"cz": 'elementární náboj', "en": 'elementary charge'}, "k":csts.q, "constant": True},
|
227
|
+
{"v": [0,0,0,0,0,-1,0,0], "id": '_NA', "name": {"cz": 'Avogadrova konstanta', "en": 'Avogadro constant'}, "k":6.02214085e23, "constant": True},
|
228
|
+
{"v": [0,0,0,0,0,0,0,0], "id": '_pi', "alias":['π'], "name": {"cz": 'Ludolfovo číslo', "en": 'Archimedes\' constant'}, "k":Math.pi, "constant": True},
|
229
|
+
{"v": [0,0,0,0,0,0,0,0], "id": '_e', "name": {"cz": 'Eulerovo číslo', "en": 'Euler\'s number'}, "k":Math.e, "constant": True},
|
230
|
+
# #special for Unitfuns, unusable without {}
|
231
|
+
# {"v": [3,-1,0,0,0,0,0,0], "id": 'API', "alias":['°API'], "name": {"cz": 'API hustota', "en": 'API density'}, "k":1/141.5e3, onlyUnitfuns: True}, #theoretically, without {} API = specific volume unit
|
232
|
+
# {"v": [0,0,0,0,0,0,0,0], "id": 'ln', "alias":['log'], "name": {"cz": 'Přirozený logaritmus', "en": 'Natural logarithm'}, "k":NaN, onlyUnitfuns: True}
|
233
|
+
];
|
234
|
+
|
235
|
+
# #unitfuns - irregular units that have a conversion function instead of mere ratio
|
236
|
+
# #{id: link to regular unit, f: function UF => SI, fi: inverse function SI => UF, "v": SI dimension (output when f, input when fi)}
|
237
|
+
# dict_Unitfuns = [
|
238
|
+
# {id: '°C', f: UF => UF + csts.TC0, fi: SI => SI - csts.TC0, "v": [0,0,0,0,1,0,0,0]},
|
239
|
+
# {id: '°F', f: UF => 5/9*UF + csts.TF0, fi: SI => 9/5*(SI - csts.TF0), "v": [0,0,0,0,1,0,0,0]},
|
240
|
+
# {id: '°Re', f: UF => 1.25*UF + csts.TC0, fi: SI => 0.8*(SI - csts.TC0), "v": [0,0,0,0,1,0,0,0]},
|
241
|
+
# {id: 'API', f: UF => csts.APIk/(UF - csts.APIq), fi: SI => csts.APIk/SI + csts.APIq, "v": [-3,1,0,0,0,0,0,0]},
|
242
|
+
# {id: 'ln', f: UF => Math.log(UF), fi: SI => {throw '🏆 '+langService.trans('ERR_Secret');}, "v": [0,0,0,0,0,0,0,0]}
|
243
|
+
# ];
|
244
|
+
|
245
|
+
#currencies - their conversion ratio to dollar is unknown and will be obtained by currencies.php
|
246
|
+
#k and v will be filled later (v is always the same, k is obtained from API)
|
247
|
+
dict_Currencies = [
|
248
|
+
{id: 'EUR', "alias":['€'], "name": {"cz": 'euro', "en": 'Euro'}},
|
249
|
+
{id: 'AED', "name": {"cz": 'dirham Spojených arabských emirátů', "en": 'United Arab Emirates Dirham'}},
|
250
|
+
{id: 'ARS', "name": {"cz": 'argentinské peso', "en": 'Argentine Peso'}},
|
251
|
+
{id: 'AUD', "name": {"cz": 'australský dolar', "en": 'Australian Dollar'}},
|
252
|
+
{id: 'BGN', "name": {"cz": 'bulharský lev', "en": 'Bulgarian Lev'}},
|
253
|
+
{id: 'BRL', "name": {"cz": 'braziliský real', "en": 'Brazilian Real'}},
|
254
|
+
{id: 'CAD', "name": {"cz": 'kanadský dolar', "en": 'Canadian Dollar'}},
|
255
|
+
{id: 'CHF', "name": {"cz": 'švýcarský frank', "en": 'Swiss Franc'}},
|
256
|
+
{id: 'CNY', "name": {"cz": 'čínský juan', "en": 'Chinese Yuan'}},
|
257
|
+
{id: 'CZK', "alias":['Kč'], "name": {"cz": 'česká koruna', "en": 'Czech Republic Koruna'}},
|
258
|
+
{id: 'DKK', "name": {"cz": 'dánská koruna', "en": 'Danish Krone'}},
|
259
|
+
{id: 'GBP', "alias":['£'], "name": {"cz": 'britská libra', "en": 'British Pound Sterling'}},
|
260
|
+
{id: 'HKD', "name": {"cz": 'hongkongský dolar', "en": 'Hong Kong Dollar'}},
|
261
|
+
{id: 'HRK', "name": {"cz": 'chorvatská kuna', "en": 'Croatian Kuna'}},
|
262
|
+
{id: 'HUF', "name": {"cz": 'maďarský forint', "en": 'Hungarian Forint'}},
|
263
|
+
{id: 'IDR', "name": {"cz": 'indonéská rupie', "en": 'Indonesian Rupiah'}},
|
264
|
+
{id: 'ILS', "name": {"cz": 'nový izraelský šekel', "en": 'Israeli New Sheqel'}},
|
265
|
+
{id: 'INR', "name": {"cz": 'indická rupie', "en": 'Indian Rupee'}},
|
266
|
+
{id: 'JPY', "alias": ['¥'], "name": {"cz": 'japonský jen', "en": 'Japanese Yen'}},
|
267
|
+
{id: 'KRW', "name": {"cz": 'jihokorejský won', "en": 'South Korean Won'}},
|
268
|
+
{id: 'MXN', "name": {"cz": 'mexické peso', "en": 'Mexican Peso'}},
|
269
|
+
{id: 'NOK', "name": {"cz": 'norská koruna', "en": 'Norwegian Krone'}},
|
270
|
+
{id: 'NZD', "name": {"cz": 'novozélandský dolar', "en": 'New Zealand Dollar'}},
|
271
|
+
{id: 'PLN', "name": {"cz": 'polský zlotý', "en": 'Polish Zloty'}},
|
272
|
+
{id: 'RON', "name": {"cz": 'rumunské leu', "en": 'Romanian Leu'}},
|
273
|
+
{id: 'RUB', "name": {"cz": 'ruský rubl', "en": 'Russian Ruble'}},
|
274
|
+
{id: 'SEK', "name": {"cz": 'švédská koruna', "en": 'Swedish Krona'}},
|
275
|
+
{id: 'SGD', "name": {"cz": 'singapurský dolar', "en": 'Singapore Dollar'}},
|
276
|
+
{id: 'THB', "name": {"cz": 'thajský baht', "en": 'Thai Baht'}},
|
277
|
+
{id: 'TRY', "name": {"cz": 'turecká lira', "en": 'Turkish Lira'}},
|
278
|
+
{id: 'VND', "name": {"cz": 'vietnamský dong', "en": 'Vietnamese Dong'}},
|
279
|
+
{id: 'ZAR', "name": {"cz": 'jihoafrický rand', "en": 'South African Rand'}},
|
280
|
+
{id: 'BTC', "name": {"cz": 'bitcoin', "en": 'Bitcoin'}}
|
281
|
+
];
|
282
|
+
|
283
|
+
#standard SI prefixes
|
284
|
+
dict_Prefixes = [
|
285
|
+
{id: 'a', "v": -18},
|
286
|
+
{id: 'f', "v": -15},
|
287
|
+
{id: 'p', "v": -12},
|
288
|
+
{id: 'n', "v": -9},
|
289
|
+
{id: 'u', "v": -6},
|
290
|
+
{id: 'μ', "v": -6},
|
291
|
+
{id: 'm', "v": -3},
|
292
|
+
{id: 'c', "v": -2},
|
293
|
+
{id: 'd', "v": -1},
|
294
|
+
{id: 'h', "v": 2},
|
295
|
+
{id: 'k', "v": 3},
|
296
|
+
{id: 'M', "v": 6},
|
297
|
+
{id: 'G', "v": 9},
|
298
|
+
{id: 'T', "v": 12},
|
299
|
+
{id: 'P', "v": 15}
|
300
|
+
];
|
301
|
+
|
302
|
+
# Define the list of dictionaries
|
303
|
+
#Extract names in the specified order
|
304
|
+
def extract_names_by_order(units_dict_list, order):
|
305
|
+
ordered_names = []
|
306
|
+
for unit in units_dict_list:
|
307
|
+
if "name" in unit:
|
308
|
+
for key in order:
|
309
|
+
if key in unit["name"]:
|
310
|
+
ordered_names.append(unit["name"][key])
|
311
|
+
return ordered_names
|
312
|
+
|
313
|
+
def make_ids_dict(units_dict_list):
|
314
|
+
ids_dict = {}
|
315
|
+
for unit_dict in units_dict_list:
|
316
|
+
if "id" in unit_dict:
|
317
|
+
ids_dict[unit_dict["id"]] = unit_dict
|
318
|
+
return ids_dict
|
319
|
+
|
320
|
+
# Specify the order of keys
|
321
|
+
name_order = ["ae", "en", "cz"]
|
322
|
+
|
323
|
+
#metric prefixes:
|
324
|
+
metric_prefixes = ["yotta", "zetta", "exa", "peta", "tera", "giga", "mega", "kilo", "hecto", "deca", "", "deci", "centi", "milli", "micro", "nano", "pico", "femto", "atto", "zepto", "yocto"]
|
325
|
+
metric_prefixes_greater = metric_prefixes[0:11] #first 10
|
326
|
+
metric_prefixes_lesser = metric_prefixes[11:]
|
327
|
+
metric_prefixes_symbolic = ["Y", "Z", "E", "P", "T", "G", "M", "k", "h", "da", "", "d", "c", "m", "µ", "n", "p", "f", "a", "z", "y"]
|
328
|
+
metric_prefixes_symbolic_greater = metric_prefixes_symbolic[0:11] #first 10
|
329
|
+
metric_prefixes_symbolic_lesser = metric_prefixes_symbolic[11:]
|
330
|
+
|
331
|
+
# Extract and print the names
|
332
|
+
ordered_name_list = extract_names_by_order(units_dict_list, name_order)
|
333
|
+
ids_dict = make_ids_dict(units_dict_list)
|
334
|
+
|
335
|
+
#now expand them with the metric prefix permutations
|
336
|
+
def expand_ids_list(ids_list, ids_dict):
|
337
|
+
"""
|
338
|
+
Gives back the expanded names list by generating permutations with metric prefixes.
|
339
|
+
Such as:
|
340
|
+
["km", "cm", "mm"]
|
341
|
+
"""
|
342
|
+
expanded_ids_list = [] #now create the list to add to.
|
343
|
+
for id in ids_list:
|
344
|
+
if "prefix" in ids_dict[id]:
|
345
|
+
if ids_dict[id]["prefix"] == "all":
|
346
|
+
for metric_prefix_symbolic in metric_prefixes_symbolic:
|
347
|
+
expanded_ids_list.append(metric_prefix_symbolic+id)
|
348
|
+
elif ids_dict[id]["prefix"] == "-":
|
349
|
+
expanded_ids_list.append(id) #no prefix
|
350
|
+
for metric_prefix_symbolic in metric_prefixes_symbolic_lesser:
|
351
|
+
expanded_ids_list.append(metric_prefix_symbolic+id)
|
352
|
+
elif ids_dict[id]["prefix"] == "+":
|
353
|
+
expanded_ids_list.append(id) #no prefix
|
354
|
+
for metric_prefix_symbolic in metric_prefixes_symbolic_greater:
|
355
|
+
expanded_ids_list.append(metric_prefix_symbolic+id)
|
356
|
+
else:
|
357
|
+
expanded_ids_list.append(id) #no prefix
|
358
|
+
else:
|
359
|
+
expanded_ids_list.append(id) #no prefix
|
360
|
+
return expanded_ids_list
|
361
|
+
ids_list = list(ids_dict.keys())
|
362
|
+
expanded_ids_list = expand_ids_list(ids_list, ids_dict)
|
363
|
+
expanded_ids_set = set(expanded_ids_list)
|
364
|
+
|
365
|
+
def expand_names_list(ids_list, ids_dict):
|
366
|
+
"""
|
367
|
+
Gives back the expanded names list by generating permutations with metric prefixes.
|
368
|
+
Such as:
|
369
|
+
["kilometer", "megameter", "gigameter"]
|
370
|
+
|
371
|
+
The lines which say ids_dict[id]["alias"][0] could loop across aliases.
|
372
|
+
However, there is usually only one alias, and the first is usually sufficient when there is more than one.
|
373
|
+
"""
|
374
|
+
expanded_names_list = [] # Create the list to add to.
|
375
|
+
for id in ids_list:
|
376
|
+
if "prefix" in ids_dict[id]:
|
377
|
+
if ids_dict[id]["prefix"] == "all": #for "all" prefix.
|
378
|
+
#loop across prefixes, includes base case.
|
379
|
+
for metric_prefix in metric_prefixes: # Use "metric_prefixes".
|
380
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["en"]) # Use ids_dict[id]["name"]["en"] for concatenation.
|
381
|
+
if 'ae' in ids_dict[id]["name"]:
|
382
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["ae"])
|
383
|
+
if 'alias' in ids_dict[id]:
|
384
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["alias"][0])
|
385
|
+
elif ids_dict[id]["prefix"] == "-": #for "-" prefix.
|
386
|
+
#base case
|
387
|
+
expanded_names_list.append(ids_dict[id]["name"]["en"]) # No prefix.
|
388
|
+
if 'ae' in ids_dict[id]["name"]:
|
389
|
+
expanded_names_list.append(ids_dict[id]["name"]["ae"]) # No prefix.
|
390
|
+
if 'alias' in ids_dict[id]:
|
391
|
+
expanded_names_list.append(ids_dict[id]["alias"][0]) #No prefix.
|
392
|
+
#loop across prefix cases
|
393
|
+
for metric_prefix in metric_prefixes_lesser: # Use lesser prefixes.
|
394
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["en"])
|
395
|
+
if 'ae' in ids_dict[id]["name"]:
|
396
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["ae"])
|
397
|
+
if 'alias' in ids_dict[id]:
|
398
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["alias"][0])
|
399
|
+
elif ids_dict[id]["prefix"] == "+": #for "+" prefix.
|
400
|
+
#base case
|
401
|
+
expanded_names_list.append(ids_dict[id]["name"]["en"]) # No prefix.
|
402
|
+
if 'ae' in ids_dict[id]["name"]:
|
403
|
+
expanded_names_list.append(ids_dict[id]["name"]["ae"]) # No prefix.
|
404
|
+
if 'alias' in ids_dict[id]:
|
405
|
+
expanded_names_list.append(ids_dict[id]["alias"][0])
|
406
|
+
#loop across prefixes
|
407
|
+
for metric_prefix in metric_prefixes_greater: # Use greater prefixes.
|
408
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["en"])
|
409
|
+
if 'ae' in ids_dict[id]["name"]:
|
410
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["name"]["ae"])
|
411
|
+
if 'alias' in ids_dict[id]:
|
412
|
+
expanded_names_list.append(metric_prefix + ids_dict[id]["alias"][0])
|
413
|
+
else: #for odd prefix rules, we just use base case.
|
414
|
+
#base case
|
415
|
+
expanded_names_list.append(ids_dict[id]["name"]["en"]) # No prefix.
|
416
|
+
if 'ae' in ids_dict[id]["name"]:
|
417
|
+
expanded_names_list.append(ids_dict[id]["name"]["ae"]) # No prefix.
|
418
|
+
if 'alias' in ids_dict[id]:
|
419
|
+
expanded_names_list.append(ids_dict[id]["alias"][0])
|
420
|
+
else: #for no prefix.
|
421
|
+
expanded_names_list.append(ids_dict[id]["name"]["en"]) # No prefix.
|
422
|
+
if 'ae' in ids_dict[id]["name"]:
|
423
|
+
expanded_names_list.append(ids_dict[id]["name"]["ae"]) # No prefix.
|
424
|
+
if 'alias' in ids_dict[id]:
|
425
|
+
expanded_names_list.append(ids_dict[id]["alias"][0])
|
426
|
+
return expanded_names_list
|
427
|
+
|
428
|
+
|
429
|
+
expanded_names_list = expand_names_list(ids_list, ids_dict)
|
430
|
+
expanded_names_set = set(expanded_names_list)
|
431
|
+
|
432
|
+
|
433
|
+
if __name__ == "__main__":
|
434
|
+
#here is just the ordered name list.
|
435
|
+
name_order = ["ae", "en", "cz"]
|
436
|
+
ordered_name_list = extract_names_by_order(units_dict_list, name_order)
|
437
|
+
print(ordered_name_list)
|
438
|
+
#here is just the ordered name list for cz names.
|
439
|
+
name_order = ["cz"]
|
440
|
+
ordered_name_list = extract_names_by_order(units_dict_list, name_order)
|
441
|
+
print(ordered_name_list)
|
442
|
+
|
443
|
+
#here is just the ordered name list for en names.
|
444
|
+
name_order = ["en"]
|
445
|
+
ordered_name_list = extract_names_by_order(units_dict_list, name_order)
|
446
|
+
print("\n", ordered_name_list)
|
447
|
+
|
448
|
+
#print the ids_list:
|
449
|
+
ids_list = make_ids_dict(units_dict_list)
|
450
|
+
print(ids_list)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# JSONGrapherRC
|
2
|
+
A python package for creating JSONGrapher Records
|
3
|
+
|
4
|
+
To use JSONGrapherRC, first install it using pip:
|
5
|
+
<pre>
|
6
|
+
pip install JSONGrapherRC[COMPLETE]
|
7
|
+
</pre>
|
8
|
+
|
9
|
+
Alternatively, you can download the directory directly.<br>
|
10
|
+
It is easiest to then follow the [example file](https://github.com/AdityaSavara/JSONGrapherRC/blob/main/example/exampleUsageJSONRecordCreator.py) to learn.<br>
|
11
|
+
|
12
|
+
|
13
|
+
## **1\. Preparing to Create a Record**
|
14
|
+
|
15
|
+
Let's create an example where we plot the height of a pear tree over several years. Assuming a pear tree grows approximately 0.40 meters per year, we'll generate sample data with some variation.
|
16
|
+
<pre>
|
17
|
+
x_label_including_units = "Time (years)"
|
18
|
+
y_label_including_units = "Height (m)"
|
19
|
+
time_in_years = [0, 1, 2, 3, 4]
|
20
|
+
tree_heights = [0, 0.42, 0.86, 1.19, 1.45]
|
21
|
+
</pre>
|
22
|
+
|
23
|
+
## **2\. Creating and Populating a New JSONGrapher Record**
|
24
|
+
|
25
|
+
The easiest way to start is with the `create_new_JSONGrapherRecord()` function. While you *can* instantiate the JSONGrapherRecord class directly, this function is generally more convenient. We'll create a record and inspect its default fields.
|
26
|
+
<pre>
|
27
|
+
try:
|
28
|
+
from JSONGRapherRC import JSONRecordCreator # Normal usage
|
29
|
+
except ImportError:
|
30
|
+
import JSONRecordCreator # If the class file is local
|
31
|
+
|
32
|
+
Record = JSONRecordCreator.create_new_JSONGrapherRecord()
|
33
|
+
Record.set_comments("Tree Growth Data collected from the US National Arboretum")
|
34
|
+
Record.set_datatype("Tree_Growth_Curve")
|
35
|
+
Record.set_x_axis_label_including_units(x_label_including_units)
|
36
|
+
Record.set_y_axis_label_including_units(y_label_including_units)
|
37
|
+
Record.add_data_series(series_name="pear tree growth", x_values=time_in_years, y_values=tree_heights, plot_type="scatter_spline")
|
38
|
+
Record.set_graph_title("Pear Tree Growth Versus Time")
|
39
|
+
</pre>
|
40
|
+
|
41
|
+
## **3\. Exporting to File**
|
42
|
+
|
43
|
+
We now have a JSONGrapher record! We can export it to a file, which can then be used with JSONGrapher.
|
44
|
+
<pre>
|
45
|
+
Record.export_to_json_file("ExampleFromTutorial.json")
|
46
|
+
Record.print_to_inspect()
|
47
|
+
</pre>
|
48
|
+
|
49
|
+
<p><strong>Expected Output:</strong></p>
|
50
|
+
<pre>
|
51
|
+
JSONGrapher Record exported to, ./ExampleFromTutorial.json
|
52
|
+
{
|
53
|
+
"comments": "Tree Growth Data collected from the US National Arboretum",
|
54
|
+
"datatype": "Tree_Growth_Curve",
|
55
|
+
"data": [
|
56
|
+
{
|
57
|
+
"name": "pear tree growth",
|
58
|
+
"x": [0, 1, 2, 3, 4],
|
59
|
+
"y": [0, 0.42, 0.86, 1.19, 1.45],
|
60
|
+
"type": "scatter",
|
61
|
+
"line": { "shape": "spline" }
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"layout": {
|
65
|
+
"title": "Pear Tree Growth Versus Time",
|
66
|
+
"xaxis": { "title": "Time (year)" },
|
67
|
+
"yaxis": { "title": "Height (m)" }
|
68
|
+
}
|
69
|
+
}
|
70
|
+
</pre>
|
71
|
+
|
72
|
+
|
73
|
+
We can also plot the data using Matplotlib and export the plot as a PNG file.
|
74
|
+
<pre>
|
75
|
+
Record.plot_with_matplotlib()
|
76
|
+
Record.export_to_matplotlib_png("ExampleFromTutorial")
|
77
|
+
</pre>
|
78
|
+
|
79
|
+
[](https://raw.githubusercontent.com/AdityaSavara/JSONGrapherRC/main/example/ExampleFromTutorial.png)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org>
|