Skip to content

Commit

Permalink
fix template_example regarding database operations
Browse files Browse the repository at this point in the history
  • Loading branch information
gituser789 committed Mar 28, 2024
1 parent eec820b commit f7cd6f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
36 changes: 8 additions & 28 deletions template_example/template_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ def Template(db):

transistor = Template(db)

# db.export_single_transistor_to_json(transistor, os.getcwd())

####################################
# Method examples
####################################
Expand All @@ -241,7 +239,8 @@ def Template(db):
# transistor.plot_v_qoss()

# connect transistors in parallel
# parallel_transistors = transistor.parallel_transistors(3)
# parallel_transistors = db.parallel_transistors(transistor, 3)
# db.export_single_transistor_to_json(parallel_transistors, os.getcwd())

# switch methods #
# transistor.switch.plot_energy_data()
Expand Down Expand Up @@ -278,38 +277,19 @@ def Template(db):
####################################

# print ALL database content
# tdb.print_tdb()
# db.print_tdb()

# print database content of housing and datasheet hyperlink
# tdb.print_tdb(['housing_type','datasheet_hyperlink'])

# before init mongo, you need to install mongodb and start the database via the command line by using 'mongo' command
# init mongodb
# collection = tdb.connect_local_tdb() # Collection

# reset the mongodb database
# collection.drop()

# store transistor
# optional argument: collection. If no collection is specified, it connects to local TDB
# transistor.save()
# db.print_tdb(['housing_type','datasheet_hyperlink'])

# load transistor
# optional argument: collection. If no collection is specified, it connects to local TDB
# transistor_loaded = tdb.load({'name': 'CREE_C3M0016120K'})
# transistor_loaded = db.load_transistor('CREE_C3M0016120K')
# print(transistor_loaded.switch.t_j_max)

# export to json
# optional argument: path. If no path is specified, saves exports to local folder
# transistor.export_json()

# import from json
# optional argument: path. If no path is specified, it loads from to local folder
# transistor_imported = tdb.import_json('CREE_C3M0016120K.json')
# print(transistor_imported.switch.t_j_max)

# Rename transistor arguments
# tdb.connect_local_tdb().update_many({}, {"$rename": {"transistor_type": "type"}})
# db.export_single_transistor_to_json(transistor, os.getcwd())

####################################
# Examples to fill-in transistor.wp-class
Expand All @@ -325,10 +305,10 @@ def Template(db):
# transistor.wp.e_oss = transistor.calc_v_eoss()
# transistor.wp.q_oss = transistor.calc_v_qoss()
#
# # switch, linearize channel and search for losscurves
# # switch, linearize channel and search for loss curves
# transistor.wp.switch_v_channel, transistor.wp.switch_r_channel = transistor.calc_lin_channel(25, 15, 150, 'switch')
# transistor.wp.e_on = transistor.get_object_i_e('e_on', 25, 15, 600, 2.5).graph_i_e
# transistor.wp.e_off = transistor.get_object_i_e('e_off', 25, -4, 600, 2.5).graph_i_e
#
# # diode, linearize channel and search for losscurves
# # diode, linearize channel and search for loss curves
# transistor.wp.diode_v_channel, transistor.wp.diode_r_channel = transistor.calc_lin_channel(25, -4, 150, 'diode')
17 changes: 14 additions & 3 deletions transistordatabase/database_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Manage the database with its different operation modes (json and mongodb)."""
# Python standard libraries
from enum import Enum
from typing import List, Dict, Union
from typing import List, Dict, Union, Optional
from datetime import datetime
from matplotlib import pyplot as plt
import numpy as np
Expand Down Expand Up @@ -686,8 +686,19 @@ def import_xml_data(files: Dict) -> Transistor:
print(e.args[0])

@staticmethod
def export_single_transistor_to_json(transistor: Transistor, file_path: str):
"""Export a single transistor object to a json file."""
def export_single_transistor_to_json(transistor: Transistor, file_path: Optional[str] = None):
"""
Export a single transistor object to a json file.
:param transistor: transistor name
:type transistor: Transistor
:param file_path: Specify a directory or a file path. In case of a directory, the transistor_name.json is used
as a file name. In case of None, the current working directory is used together with
the transistor_name.json as a file name.
:type file_path: Optional[str]
"""
if file_path is None:
file_path = os.getcwd()
if os.path.isdir(file_path):
file_path = os.path.join(file_path, f"{transistor.name}.json")
print(file_path)
Expand Down

0 comments on commit f7cd6f8

Please sign in to comment.