-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from jrsmth/develop
Develop
- Loading branch information
Showing
10 changed files
with
112 additions
and
92 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
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
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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import json | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
import jsons as jsons | ||
from munch import Munch | ||
|
||
|
||
class Base: | ||
@dataclass | ||
class Base(ABC): | ||
""" Model Base Class """ | ||
|
||
def __init__(self, d=None): | ||
""" Constructor that optionally converts dict to obj """ | ||
if d is not None: | ||
for key, value in d.items(): | ||
if type(value) is dict: | ||
setattr(self, key, Munch().fromDict(value)) | ||
else: | ||
setattr(self, key, value) | ||
@classmethod | ||
@abstractmethod | ||
def from_dict(cls, dic): | ||
""" Convert a dictionary to a python object """ | ||
pass | ||
|
||
def to_string(self): | ||
@classmethod | ||
def from_json(cls, json_str: str): | ||
""" Convert a json string to a python object """ | ||
return cls.from_dict(json.loads(json_str)) | ||
|
||
@classmethod | ||
def to_string(cls): | ||
""" Converts a complex object into a string """ | ||
return str(jsons.dump(self)) | ||
return str(jsons.dump(cls)) |
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
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
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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
from dataclasses import dataclass | ||
|
||
from src.app.model.base import Base | ||
|
||
|
||
@dataclass | ||
class Player(Base): | ||
""" Tracked player information """ | ||
name = '' | ||
streak = 0 | ||
score = 0 | ||
name: str | ||
streak: int | ||
score: int | ||
|
||
@classmethod | ||
def from_dict(cls, dic): | ||
return cls( | ||
name=dic["name"], | ||
streak=dic["streak"], | ||
score=dic["score"] | ||
) |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
from dataclasses import dataclass | ||
from src.app.model.base import Base | ||
|
||
|
||
@dataclass | ||
class Record(Base): | ||
""" Tracked Record for the Historic Streaks """ | ||
name = '' | ||
streak = 0 | ||
date = '0/0/0000' | ||
name: str | ||
streak: int | ||
date: str # TODO :: actual date | ||
|
||
@classmethod | ||
def from_dict(cls, dic): | ||
return cls( | ||
name=dic["name"], | ||
streak=dic["streak"], | ||
date=dic["date"] | ||
) |
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ pyjavaproperties~=0.7 | |
from_root | ||
Munch | ||
pytest | ||
jsonpickle |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.2-SNAPSHOT" | ||
__version__ = "0.2.0-SNAPSHOT" |