Skip to content

Commit

Permalink
streamlined book and chapter structure
Browse files Browse the repository at this point in the history
Signed-off-by: WithPrecedent <coreyrayburnyung@gmail.com>
  • Loading branch information
WithPrecedent committed Apr 13, 2020
1 parent 6acc775 commit d7d6157
Show file tree
Hide file tree
Showing 21 changed files with 787 additions and 1,028 deletions.
14 changes: 3 additions & 11 deletions simplify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
:license: Apache-2.0
"""

from simplify.core.base import SimpleSystem
from simplify.core.base import SimpleCreator
from simplify.core.base import SimpleSimpleRepository
from simplify.core.base import SimpleRepository
from simplify.core.base import SimpleComponent
from simplify.core.dataset import Dataset
from simplify.core.filer import Filer
from simplify.core.idea import Idea
from simplify.core.project import Project
from simplify.core.worker import Worker
from simplify.core.utilities import simple_timer


Expand All @@ -23,13 +19,9 @@
__author__ = 'Corey Rayburn Yung'

__all__ = [
'SimpleSystem',
'SimpleCreator',
'SimpleSimpleRepository',
'SimpleRepository',
'SimpleComponent',
'Dataset',
'Filer',
'Idea',
'Project',
'timer']
'Worker',
'simple_timer']
66 changes: 4 additions & 62 deletions simplify/core/author.py → simplify/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@dataclasses.dataclass
class Author(base.SimpleHandler, base.SimpleProxy):
class Author(base.SimpleHandler, core.SimpleProxy):
"""Generic subpackage controller class for siMpLify data projects.
Args:
Expand All @@ -28,7 +28,7 @@ class Author(base.SimpleHandler, base.SimpleProxy):
as the base class for effective coordination between siMpLify
classes. Defaults to None or __class__.__name__.lower().
idea (Optional['Idea']): shared project configuration settings.
options (Optional['SimpleRepository']):
options (Optional[core.SimpleRepository]):
book (Optional['Book']):
auto_draft (Optional[bool]): whether to call the 'draft' method when
instanced. Defaults to True.
Expand All @@ -41,8 +41,8 @@ class Author(base.SimpleHandler, base.SimpleProxy):
"""
name: Optional[str] = None
idea: Optional['configuration.Idea'] = None
options: Optional['base.SimpleRepository'] = dataclasses.field(
default_factory = base.SimpleRepository)
options: Optional['core.SimpleRepository'] = dataclasses.field(
default_factory = core.SimpleRepository)

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand All @@ -51,24 +51,6 @@ def __post_init__(self) -> None:

""" Core siMpLify Methods """

def outline(self) -> Dict[str, List[str]]:
"""Creates dictionary with techniques for each step.
Returns:
Dict[str, Dict[str, List[str]]]: dictionary with keys of steps and
values of lists of techniques.
"""
steps = self._get_settings(
section = self.name,
prefix = self.name,
suffix = 'steps')
return {
step: self._get_settings(
section = self.name,
prefix = step,
suffix = 'techniques')
for step in steps}

def draft(self) -> None:
"""Activates and instances select attributes."""
Expand Down Expand Up @@ -99,44 +81,4 @@ def _get_settings(self,
"""
return utilities.listify(self.idea[section]['_'.join([prefix, suffix])])

def _draft_comparer(self) -> None:
"""Drafts 'Book' instance with a parallel chapter structure.
Args:
project ('Project'): an instance for a 'Book' instance to be
modified.
Returns:
'Project': with 'Book' instance modified.

"""
# Creates list of steps from 'project'.
steps = list(self.overview[self.name].keys())
# Creates 'possible' list of lists of 'techniques'.
possible = list(self.overview[self.name].values())
# Creates a list of lists of the Cartesian product of 'possible'.
combinations = list(map(list, itertools.product(*possible)))
# Creates Chapter instance for every combination of techniques.
for techniques in combinations:
step_pairs = tuple(zip(steps, techniques))
chapter = self.instructions.chapter(steps = step_pairs)
self.book.chapters.append(chapter)
return project

def _draft_sequencer(self) -> None:
"""Drafts 'Book' instance with a serial 'techniques' structure.
Args:
project ('Project'): an instance for a 'Book' instance to be
modified.
Returns:
'Project': with 'Book' instance modified.
"""
new_steps = []
for step, techniques in project.overview[self.worker.name].items():
for technique in techniques:
new_steps.append((step, technique))
project[self.worker.name].steps.extend(new_steps)
return project
32 changes: 17 additions & 15 deletions simplify/core/book.py → simplify/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
:license: Apache-2.0
"""

import abc
import collections.abc
import dataclasses
import importlib
import types
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union

from simplify import core


@dataclasses.dataclass
class Book(base.SimpleRepository, base.SimpleProxy):
class Book(core.SimplePlan, core.SimpleProxy):
"""Top-level siMpLify iterable for a 'Worker'.
Args:
Expand All @@ -26,23 +26,24 @@ class Book(base.SimpleRepository, base.SimpleProxy):
When subclassing, it is a good idea to use the same 'name' attribute
as the base class for effective coordination between siMpLify
classes. Defaults to None or __class__.__name__.lower().
chapters (Optional['SimpleRepository']): iterable collection of
'Chapter' instances. Defaults to an empty 'SimpleRepository'.
chapters (Optional[core.SimplePlan]): iterable collection of
'Chapter' instances. Defaults to an empty core.SimplePlan.
"""
name: Optional[str] = None
chapters: Optional['SimpleRepository'] = dataclasses.field(
default_factory = base.SimpleRepository)
chapters: Optional[core.SimplePlan] = dataclasses.field(
default_factory = core.SimplePlan)

def __post_init__(self) -> None:
"""Converts 'chapters' to a property for 'contents' attribute."""
super().__post_init__()
self.contents = self.chapters
self.proxify(proxy = 'chapters', name = 'contents')
return self


@dataclasses.dataclass
class Chapter(base.SimpleRepository, base.SimpleProxy):
class Chapter(core.SimplePlan, core.SimpleProxy):
"""Standard class for siMpLify nested iterable storage.
Args:
Expand All @@ -53,23 +54,24 @@ class Chapter(base.SimpleRepository, base.SimpleProxy):
When subclassing, it is a good idea to use the same 'name' attribute
as the base class for effective coordination between siMpLify
classes. Defaults to None or __class__.__name__.lower().
techniques (Optional['SimpleRepository']): iterable collection of
'Technique' instances. Defaults to an empty 'SimpleRepository'.
techniques (Optional[core.SimplePlan]): iterable collection of
'Technique' instances. Defaults to an empty core.SimplePlan.
"""
name: Optional[str] = None
techniques: Optional['SimpleRepository'] = dataclasses.field(
default_factory = base.SimpleRepository)
techniques: Optional[core.SimplePlan] = dataclasses.field(
default_factory = core.SimplePlan)

def __post_init__(self) -> None:
"""Converts 'techniques' to a property for 'contents' attribute."""
super().__post_init__()
self.contents = self.techniques
self.proxify(proxy = 'techniques', name = 'contents')
return self


@dataclasses.dataclass
class Technique(base.SimpleComponent):
class Technique(core.SimpleLoader):
"""Base method wrapper for applying algorithms to data.
Args:
Expand Down Expand Up @@ -113,7 +115,7 @@ def __str__(self) -> str:


@dataclasses.dataclass
class Parameters(structure.SimpleRepository):
class Parameters(core.SimpleRepository):
"""Base class for constructing and storing 'Technique' parameters.
Args:
Expand All @@ -130,7 +132,7 @@ class Parameters(structure.SimpleRepository):


@dataclasses.dataclass
class Expert(base.SimpleCreator):
class Expert(core.SimpleHandler):

worker: 'Worker'

Expand Down
File renamed without changes.
102 changes: 20 additions & 82 deletions simplify/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,30 @@
"""
.. module:: creator
:synopsis: functional data science made simple
.. module:: core
:synopsis: siMpLify base classes and utilities
:author: Corey Rayburn Yung
:copyright: 2019-2020
:license: Apache-2.0
"""

import numpy as np
import pandas as pd
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
from simplify.core.component import SimpleComponent
from simplify.core.component import SimpleLoader
from simplify.core.component import SimplePlan
from simplify.core.component import SimpleProxy
from simplify.core.component import SimpleRepository
from simplify.core.handler import SimpleHandler
from simplify.core.handler import SimpleParallel
from simplify.core.system import SimpleSystem

from simplify.core.idea import Idea
from simplify.core.library import Book
from simplify.core.creators import Publisher
from simplify.core.dataset import Dataset
from simplify.core.filer import Filer
from simplify.core.manager import Package
from simplify.core.project import Project

from simplify.core.scholar import Scholar
__version__ = '0.1.1'

__all__ = [
'Idea',
'Book',
'Dataset',
'Filer',
'Publisher',
'Scholar',
'Project',
'Package']


# def startup(
# idea: Union['Idea', Dict[str, Dict[str, Any]], str],
# filer: Union['Filer', str],
# dataset: Union[
# 'Dataset',
# pd.DataFrame,
# pd.Series,
# np.ndarray,
# str,
# List[Union[
# 'Data',
# pd.DataFrame,
# pd.Series,
# np.ndarray,
# str]],
# Dict[str, Union[
# 'Data',
# pd.DataFrame,
# pd.Series,
# np.ndarray,
# str]]],
# project: 'Project') -> None:
# """Creates and/or conforms Idea, Filer, and Dataset instances.
__author__ = 'Corey Rayburn Yung'

# Args:
# idea (Union['Idea', Dict[str, Dict[str, Any]], str]): an instance of
# Idea, a nested Idea-compatible nested dictionary, or a string
# containing the file path where a file of a supoorted file type with
# settings for an Idea instance is located.
# filer (Union['Filer', str]): an instance of Filer or a
# string containing the full path of where the root folder should be
# located for file output. A Filer instance contains all file path
# and import/export methods for use throughout the siMpLify package.
# dataset (Union['Dataset', pd.DataFrame, pd.Series, np.ndarray,
# str, List[Union[pd.DataFrame, pd.Series, np.ndarray, str]],
# Dict[str, Union[pd.DataFrame, pd.Series, np.ndarray, str]]]): an
# instance of Dataset, a string containing the full file
# path where a data file for a pandas DataFrame or Series is located,
# a string containing a file name in the default data folder, as
# defined in the shared Filer instance, a DataFrame, a Series,
# numpy ndarray, a list of data objects, or dict with data objects as
# values. If a DataFrame, ndarray, or string is provided, the
# resultant DataFrame is stored at the 'df' attribute in a new
# Dataset instance. If a list is provided, each data object is
# stored as 'df' + an integer based upon the order of the data
# objct in the list.
# project ('Project'): a related Project instance.

# Returns:
# Idea, Filer, Dataset instances.

# """
# idea = Idea.create(idea = idea)
# Filer.idea = idea
# filer = Filer.create(root_folder = filer)
# Dataset.idea = idea
# Dataset.filer = filer
# dataset = Dataset.create(data = dataset)
# return idea, filer, dataset
__all__ = [
'SimpleComponent',
'SimplePlan',
'SimpleProxy',
'SimpleRepository'
'SimpleHandler',
'SimpleParallel',
'SimpleSystem']

0 comments on commit d7d6157

Please sign in to comment.