Skip to content

Commit

Permalink
20220722 Event Cullers for the GUI
Browse files Browse the repository at this point in the history
Added N Occurrences event culler
  • Loading branch information
Michaeljfang committed Jul 22, 2022
1 parent 8dfa17a commit 8557895
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# PyGAAP Constants
version = "1.0.0 alpha 1"
versiondate = "2022.07.21"
versiondate = "2022.07.22"
8 changes: 7 additions & 1 deletion Developer_Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ edit_known_authors(.., mode) #called when a button in

# Adding a new module <a name="new_mod"></a>
Each module is a class in or imported to the file containing modules of the same type. These types are canonicizers (```Canonicizer.py```), event drivers (```EventDriver.py```), event cullers (```EventCulling.py```), analysis methods (```AnalysisMethod.py```), and distance functions (```DistanceFunction.py```). If a module is not in one of those py files (i.e. imported into them), it is an "external module". For the purpose of this manual, external modules do not include libraries or files not directly called by the API (e.g. sklearn).
Add package dependencies and their version numbers to ```./requirements.txt```, if applicable.
Add package dependencies and their version numbers to ```./requirements.txt```, if applicable.\
As a readability consideration, it's recommended that the files for external modules be prefixed with the following:\
```cc``` for canonicizers\
```ed``` for event drivers\
```ec``` for event cullers\
```am``` for analysis methods\
```df``` for distance functions.

## <span style="color:#aaeeff">Class variables</span> <a name="class_variables"></a>
Class variables are declared within the class definition.
Expand Down
2 changes: 1 addition & 1 deletion PyGAAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main():
cliMain()
else:
# import backend.GUI.GUI
from .backend.GUI import GUI2
from backend.GUI import GUI2
app = GUI2.PyGAAP_GUI()
app.run()

Expand Down
8 changes: 6 additions & 2 deletions backend/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,21 @@ def runAnalysis(self, analysisMethodString, distanceFunctionString):
analysis.train(knownDocs)
return unknownDoc, analysis.analyze(unknownDoc)

def prettyFormatResults(self, canonicizers, eventDrivers, analysisMethod, distanceFunc, unknownDoc, results):
def prettyFormatResults(self, canonicizers, eventDrivers, eventCullers, analysisMethod, distanceFunc, unknownDoc, results):
'''Returns a string of the results in a pretty, formatted structure.'''
# Build a string the contains general information about the experiment.
formattedResults = str(unknownDoc.title) + ' ' + str(unknownDoc.filepath) + "\nCanonicizers:\n"
for canonicizer in canonicizers:
formattedResults += '\t' + canonicizer + '\n'
if type(eventDrivers) == list:
for eventDriver in eventDrivers:
formattedResults += '\t' + eventDriver + '\n'
formattedResults += "Event Drivers:\n\t" + eventDriver + '\n'
else:
formattedResults += "Event Driver:\n\t" + eventDrivers + '\n'

for eventCuller in eventCullers:
formattedResults += "Event Culler:\n\t" + eventCuller + '\n'

formattedResults += "Analysis Method:\n\t" + analysisMethod + " with " + distanceFunc + '\n'

# Sort the dictionary in ascending order by distance values and build the results listing.
Expand Down
3 changes: 2 additions & 1 deletion backend/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def cliMain():
api.runEventDriver(eventDriver)

# Run the analysis and get the results in a formatted string.
# TODO implement event culling for the CLI
unknownDoc, results = api.runAnalysis(analysisMethod, distanceFunc)
formattedResults = api.prettyFormatResults(canonicizers, eventDriver, analysisMethod, distanceFunc, unknownDoc, results)
formattedResults = api.prettyFormatResults(canonicizers, eventDriver, "", analysisMethod, distanceFunc, unknownDoc, results)

# Create the directories that the results will be stored in.
outPath = os.path.join(Path.cwd(), "tmp", '&'.join(canonicizers).replace('|', '_').replace(':', '_'), eventDriver.replace('|', '_').replace(':', '_'), analysisMethod + '-' + distanceFunc)
Expand Down
7 changes: 4 additions & 3 deletions backend/GUI/GUI_run_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def run_pre_processing(
doc.setEventSet(event_set, append=True)
#print("evset----------------", doc.eventSet[:15])

if len(self.backend_API.modulesInUse["EventCulling"]) != 0:
raise NotImplementedError
#?._global_parameters = self.backend_API.global_parameters
for ec in self.backend_API.modulesInUse["EventCulling"]:
ec._global_parameters = self.backend_API.global_parameters
doc.setEventSet(ec.process(doc.eventSet))
return doc

def run_experiment(self):
Expand Down Expand Up @@ -182,6 +182,7 @@ def run_experiment(self):
formatted_results = \
self.backend_API.prettyFormatResults(self.module_names["canonicizers_names"],
self.module_names["event_drivers_names"],
self.module_names["event_cullers_names"],
self.module_names["am_df_names"][am_df_index][0],
self.module_names["am_df_names"][am_df_index][1],
d,
Expand Down
25 changes: 13 additions & 12 deletions generics/EventCulling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
self._variable_options = dict()

@abstractmethod
def process(self, procText):
def process(self, eventSet):
'''To be determined'''
pass

Expand All @@ -33,20 +33,21 @@ def displayDescription():
'''Returns the display description for the event culler.'''


class EmptyEventCuller(EventCulling):
_variable_options={"test_param1": {"options": list(range(2, 8)), "default": 0, "type": "OptionMenu"},
"test_param2": {"options": list(range(10, 15)), "default": 4, "type": "OptionMenu"},
"test_param3": {"options": ["op1", "op2"], "default": 0, "type": "OptionMenu"}}
class N_Occurrences(EventCulling):
_variable_options = {"Frequency": {"options": list(range(1, 5)), "default": 0, "type": "OptionMenu"}}

test_param1 = _variable_options["test_param1"]["options"][_variable_options["test_param1"]["default"]]
test_param2 = _variable_options["test_param2"]["options"][_variable_options["test_param2"]["default"]]
test_param3 = _variable_options["test_param3"]["options"][_variable_options["test_param3"]["default"]]
Frequency = _variable_options["Frequency"]["options"][_variable_options["Frequency"]["default"]]

def process(self, procText):
pass
def process(self, eventSet: list):
freq = dict()
for e in eventSet:
if freq.get(e) == None: freq[e] = 1
else: freq[e] += 1
new_events = [ev for ev in eventSet if (freq.get(ev)!=None and freq.get(ev) > 1)]
return new_events

def displayName():
return "Test event culler"
return "N occurrences"

def displayDescription():
return "An empty event culler class."
return "Remove features that are encountered N or fewer times."

0 comments on commit 8557895

Please sign in to comment.