Skip to content

Commit

Permalink
Merge pull request #2 from foarsitter/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
foarsitter authored Nov 6, 2017
2 parents bb7ffe1 + cea429d commit 0461461
Show file tree
Hide file tree
Showing 26 changed files with 1,240 additions and 883 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ data/
.idea/
model-settings.xml
*.pyc
model/__pycache__/
model/helpers/__pycache__/
model/observers/__pycache__/
sample_data/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python:
- "3.5"
# command to run tests
install:
- pip install codecov coverage codeclimate-test-reporter
- pip install codecov coverage codeclimate-test-reporter scipy
script: nosetests --with-coverage --cover-erase
after_success:
- coverage
Expand Down
32 changes: 21 additions & 11 deletions decide-gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from tkinter import messagebox
from tkinter import ttk

import decimal

from model.base import AbstractModel
from model.helpers import csvParser
from model.helpers import csvparser
from model.helpers.helpers import ModelLoop
from model.observers.exchanges_writer import ExchangesWriter
from model.observers.externalities import Externalities
from model.observers.issue_development import IssueDevelopment
from model.observers.logger import Logger
from model.observers.observer import Observable, Observer


Expand Down Expand Up @@ -201,6 +202,9 @@ def __init__(self, parent, *args, **kwargs):
self.salience_weight = tk.DoubleVar()
self.salience_weight.set(0.4)

self.randomized_value = tk.DoubleVar()
self.randomized_value.set(0.1)

self.fixed_weight = tk.DoubleVar()
self.fixed_weight.set(0.1)

Expand Down Expand Up @@ -231,6 +235,8 @@ def __init__(self, parent, *args, **kwargs):
self.E1 = ttk.Entry(parent, textvariable=self.iterations)
self.E1.grid(row=row, column=1, sticky=tk.W)

self.entry_row("Model repetitions", self.repetitions)

row = self.row()
self.label("Exchange type", row=row)
r1 = ttk.Radiobutton(parent, text="Equal Exchange Rate", variable=self.model, value="equal")
Expand All @@ -239,7 +245,7 @@ def __init__(self, parent, *args, **kwargs):
r2 = ttk.Radiobutton(parent, text="Random Exchange Rate", variable=self.model, value="random")
r2.grid(row=self.row(), column=1, sticky=tk.W)

self.entry_row("Model repetitions", self.repetitions)
self.entry_row("Randomized equal gain value", self.randomized_value)
self.entry_row("Salience Weight", self.salience_weight)
self.entry_row("Fixed Weight", self.fixed_weight)

Expand Down Expand Up @@ -274,8 +280,8 @@ def input(self):

model = AbstractModel()

from model.helpers import csvParser
csv_parser = csvParser.Parser(model)
from model.helpers import csvparser
csv_parser = csvparser.CsvParser(model)

model = csv_parser.read(self.input_file.get())

Expand All @@ -290,9 +296,6 @@ def output(self):

self.output_dir.set(selected_dir)

def model_type(self):
print(self.model.get())

@staticmethod
def col():
ret = MainApplication.GRID_COLUMN
Expand Down Expand Up @@ -342,7 +345,10 @@ def to_xml(self):
for key, value in self.__dict__.items():
if isinstance(value, tk.Variable) and key not in ignore:
child = ET.Element(key)
child.text = str(value.get())
try:
child.text = str(value.get())
except tk.TclError:
child.text = str('')
element.append(child)

return element
Expand All @@ -367,18 +373,22 @@ def run(self):

if self.model.get() == "equal":
from model.equalgain import EqualGainModel as Model
try:
model = Model(randomized_value=decimal.Decimal(self.randomized_value.get()))
except tk.TclError:
model = Model(randomized_value=None)
else:
from model.randomrate import RandomRateModel as Model
model = Model()

# The event handlers for logging and writing the results to the disk.

output_directory = os.path.join(self.output_dir.get(), self.input_file.get().split("/")[-1].split(".")[0], self.model.get())

model = Model()
event_handler = Observable(model_ref=model, output_directory=output_directory)
event_handler.log(message="Start calculation at {0}".format(start_time))

csv_parser = csvParser.Parser(model_ref=model)
csv_parser = csvparser.CsvParser(model_ref=model)

if not os.path.isdir(output_directory):
os.makedirs(output_directory)
Expand Down
37 changes: 23 additions & 14 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import os
from datetime import datetime

from model.helpers import helpers, csvParser
from model.helpers.helpers import ModelLoop
from model.observers.exchanges_writer import ExchangesWriter
from model.observers.externalities import Externalities
from model.observers.issue_development import IssueDevelopment
from model.observers.observer import Observable
import decimal

if __name__ == "__main__":

import os
from datetime import datetime

from model.helpers import helpers, csvparser
from model.helpers.helpers import ModelLoop
from model.observers.exchanges_writer import ExchangesWriter
from model.observers.externalities import Externalities
from model.observers.issue_development import IssueDevelopment
from model.observers.observer import Observable

args = helpers.parse_arguments()
input_file = args.input
output_dir = args.output
Expand All @@ -21,19 +23,26 @@
os.makedirs(output_directory)

if args.model == "equal":
from model.equalgain import EqualGainModel as Model
import model.equalgain as Model

if args.p != 'None':
p = decimal.Decimal(args.p)
else:
p = None

model = Model.EqualGainModel(randomized_value=p)
else:
from model.randomrate import RandomRateModel as Model
import model.randomrate as Model

startTime = datetime.now()
model = Model.RandomRateModel()

model = Model()
startTime = datetime.now()

# The event handlers for logging and writing the results to the disk.
eventHandler = Observable(model_ref=model, output_directory=output_directory)
eventHandler.log(message="Start calculation at {0}".format(startTime))

csvParser = csvParser.Parser(model)
csvParser = csvparser.CsvParser(model)

Externalities(eventHandler)
ExchangesWriter(eventHandler)
Expand Down
Loading

0 comments on commit 0461461

Please sign in to comment.