Commit 54508fd9 authored by jay's avatar jay
Browse files

Control module with a single 'C' class to represent control networks as pandas dataframes

parent 83e0c06e
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+68 −0
Original line number Diff line number Diff line
from time import gmtime, strftime

import pandas as pd


class CSeries(pd.Series):
    """
    A custom pandas series that can accept additional methods
    """
    @property
    def _constructor(self):
        return CustomSeries


class C(pd.DataFrame):
    """
    Control network.

    Parameters
    ----------

    Attributes
    ----------

    n : int
        Number of control points

    m : int
        Number of control measures

    creationdate : str
                   The date that this control network was created.
    """
    def __init__(self, *args,**kwargs):
        super(C, self).__init__(*args, **kwargs)
        self._creationdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())

    @property
    def _constructor(self):
        return C

    _constructor_sliced = CSeries

    @property
    def n(self):
        if not getattr(self, '_n', None):
            self._n = 100
        return self._n

    @property
    def m(self):
        if not getattr(self, '_m', None):
            self._m = 500
        return self._m

    @property
    def creationdate(self):
        return self._creationdate

    @property
    def modifieddate(self):
        if not getattr(self, '_modifieddate', None):
            self._modifieddate = 'Not modified'
        return self._modifieddate

    @modifieddate.setter
    def update_modifieddate(self):
        self._modifieddate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
+0 −0

Empty file added.

+19 −0
Original line number Diff line number Diff line
import os
import sys
import unittest

sys.path.insert(0, os.path.abspath('..'))

from autocnet.control import control


class TestC(unittest.TestCase):

    def setUp(self):
        self.C = control.C()

    def test_n_point(self):
        self.assertEqual(self.C.n, 100)

    def test_n_measures(self):
        self.assertEqual(self.C.m, 500)
 No newline at end of file