-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import random | ||
|
||
import set_path | ||
from i_data import Data_type | ||
from i_structures.chemical_formulae import common_chem_elements | ||
from i_calculations.topas import get_pattern_name | ||
|
||
|
||
common_chem_elements = common_chem_elements.split() | ||
POSSIBLE_CONTENT = list(range(42)) | ||
|
||
|
||
def gen_data_item(data_type): | ||
meta = {} | ||
content = random.choice(POSSIBLE_CONTENT) | ||
|
||
if data_type == Data_type.calculation: | ||
meta["name"] = gen_chem_formula() | ||
|
||
elif data_type == Data_type.structure: | ||
meta["name"] = gen_chem_formula() | ||
|
||
elif data_type == Data_type.property: | ||
meta["name"] = gen_chem_formula() # FIXME | ||
|
||
elif data_type == Data_type.pattern: | ||
meta["name"] = get_pattern_name() | ||
|
||
else: | ||
raise RuntimeError | ||
|
||
return (meta, content, data_type) | ||
|
||
|
||
def gen_chem_formula(): | ||
els = set() | ||
pseudo_formula = "" | ||
|
||
for _ in range(random.randint(1, 7)): | ||
els.add(random.choice(common_chem_elements)) | ||
|
||
els = list(els) | ||
|
||
for n in range(len(els)): | ||
coeff = random.randint(1, 10) | ||
coeff = "" if coeff == 1 else str(coeff) | ||
pseudo_formula += els[n] + coeff | ||
|
||
return pseudo_formula | ||
|
||
|
||
if __name__ == "__main__": | ||
print(gen_chem_formula()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sys, os.path | ||
|
||
INCL_PATH = os.path.realpath( | ||
os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")) | ||
) | ||
|
||
if not INCL_PATH in sys.path: | ||
sys.path.insert(0, INCL_PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import random | ||
import logging | ||
|
||
from helpers import gen_data_item | ||
|
||
import set_path | ||
from i_data import Data_type | ||
from utils import get_data_storage | ||
|
||
|
||
FAKE_NODES = 5000 | ||
FAKE_LINKS = 5000 | ||
|
||
ALLOWED_TRANSITIONS = ( | ||
(Data_type.structure, Data_type.property), | ||
(Data_type.structure, Data_type.pattern), | ||
(Data_type.pattern, Data_type.structure), | ||
(Data_type.pattern, Data_type.property), | ||
(Data_type.property, Data_type.structure), | ||
(Data_type.property, Data_type.pattern), | ||
) | ||
|
||
db = get_data_storage() | ||
used_uuids = {} | ||
|
||
for _ in range(FAKE_NODES): | ||
selected_dtype = random.choice( | ||
( | ||
Data_type.calculation, | ||
Data_type.structure, | ||
Data_type.property, | ||
Data_type.pattern, | ||
) | ||
) | ||
used_uuids.setdefault(selected_dtype, []).append( | ||
db.put_item(*gen_data_item(selected_dtype)) | ||
) | ||
|
||
count_links, num_iters = 0, 0 | ||
|
||
while True: | ||
source_dtype, target_dtype = random.choice(ALLOWED_TRANSITIONS) | ||
source, target = random.choice(used_uuids[source_dtype]), random.choice( | ||
used_uuids[target_dtype] | ||
) | ||
|
||
if db.put_link(source, target): | ||
count_links += 1 | ||
# else: | ||
# logging.warning('Duplicate link between %s and %s occured on %s-th step' % (source, target, count_links)) | ||
|
||
if count_links == FAKE_LINKS: | ||
break | ||
|
||
num_iters += 1 | ||
if num_iters > FAKE_LINKS * 3: | ||
break | ||
|
||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import random | ||
import logging | ||
|
||
from helpers import POSSIBLE_CONTENT | ||
|
||
import set_path | ||
from utils import get_data_storage | ||
|
||
|
||
db = get_data_storage() | ||
|
||
accumulated = [] | ||
|
||
for _ in range(100): | ||
logging.warning("=" * 100) | ||
|
||
found = db.search_item(random.choice(POSSIBLE_CONTENT)) | ||
assert found | ||
|
||
item = db.get_item(found["uuid"], with_links=True) | ||
|
||
accumulated += [found["uuid"]] | ||
accumulated += item["children"] | ||
accumulated += item["parents"] | ||
logging.warning("Collected %s items" % len(accumulated)) | ||
|
||
items = db.get_items(accumulated, with_links=True) | ||
|
||
children, parents = [], [] | ||
for one in items: | ||
children += one["children"] | ||
parents += one["parents"] | ||
|
||
logging.warning("Got %s children and %s parents" % (len(children), len(parents))) | ||
|
||
db.close() |