コード例 #1
0
    def __init__(self, da=None, **kw):
        super().__init__(da=da, **kw)
        a, b, c, d = self.select_table, T('UnitID'), T('UserSettings'), T('EquipType')
        date_col = 'DateAdded'

        q = Query.from_(a) \
            .left_join(b).on_field('Unit') \
            .left_join(c).on(a.CreatedBy == c.UserName) \
            .left_join(d).on(b.Model == d.Model) \

        f.set_self(vars())

        self.default_dtypes |= \
            f.dtypes_dict('Int64', ['SMR', 'Unit SMR', 'Comp SMR', 'Part SMR', 'Pics']) | \
            f.dtypes_dict('bool', ['Comp CO'])
コード例 #2
0
    def set_static_dfs(self, df: pd.DataFrame, reset: bool = False) -> None:
        """Set static dict copies of df string value + colors for faster display in table.

        Parameters
        ----------
        df : pd.DataFrame
            full df or single row
        reset : bool
            reset static dfs if true, else append
        """

        # update all int column display format
        # NOTE this updates TableView's formats too (shared obj)
        int_cols = list(df.select_dtypes(int).columns)
        self.formats |= f.dtypes_dict('{:,.0f}', int_cols)

        static_dfs_new = self.get_static_dfs(df=df)
        static_dfs_orig = [self.m_display, self.m_color_bg, self.m_color_text]

        if reset:
            self.m_display, self.m_color_bg, self.m_color_text = static_dfs_new
        else:
            # called when adding a single row
            for m_new, m_orig in zip(static_dfs_new, static_dfs_orig):
                self.update_static_df(m_new=m_new, m_update=m_orig)

        self.set_stylemap(df=df)
コード例 #3
0
    def __init__(self, da=None, **kw):
        super().__init__(da=da, **kw)
        a, b = pk.Tables('Downtime', 'UnitID')
        q = Query.from_(a) \
            .inner_join(b).on_field('Unit')

        self.default_dtypes.update(
            **f.dtypes_dict('float64', ['Total', 'SMS', 'Suncor']))

        f.set_self(vars())
コード例 #4
0
    def __init__(self, **kw):
        super().__init__(**kw)
        a = self.select_table
        cols = [
            a.MineSite, a.Model, a.Unit, a.Component, a.Modifier, a.bench_smr,
            a.CurrentUnitSMR, a.SMRLastCO, a.CurrentComponentSMR,
            a.PredictedCODate, a.LifeRemaining, a.SNInstalled
        ]

        q = Query.from_(a) \
            .orderby(a.MineSite, a.Unit)

        f.set_self(vars())

        self.default_dtypes |= f.dtypes_dict('Int64', [
            'Bench SMR', 'Curr Unit SMR', 'SMR Last CO', 'Curr Comp SMR',
            'Life Remaining'
        ])
コード例 #5
0
    def __init__(self, da=None, **kw):
        super().__init__(da=da, **kw)
        a = self.select_table
        b, c, d, e = pk.Tables('FCSummary', 'FCSummaryMineSite', 'UnitID', 'EquipType')

        self.default_dtypes.update(
            **f.dtypes_dict('Int64', ['SMR', 'Pics']))

        self.formats.update({
            'SMR': '{:,.0f}',
            'Pics': '{:,.0f}'})

        q = Query.from_(a) \
            .left_join(b).on_field('FCNumber') \
            .left_join(d).on(d.Unit == a.Unit) \
            .left_join(c).on((c.FCNumber == a.FCNumber) & (c.MineSite == d.MineSite)) \
            .left_join(e).on(d.Model == e.Model)

        f.set_self(vars())
コード例 #6
0
    def __init__(self,
                 d_rng: Tuple[dt, dt] = None,
                 period_name: str = None,
                 model: str = '980%',
                 minesite: str = 'FortHills',
                 period: str = 'month',
                 unit: str = None):
        super().__init__()
        self.view_cols.update(ma_target='MA Target',
                              hrs_period_ma='Hrs Period MA',
                              hrs_period_pa='Hrs Period PA')

        self.default_dtypes.update(
            **f.dtypes_dict('float', ['ExcludeHours_MA', 'ExcludeHours_PA']))

        self.formats.update({
            'MA Target': '{:.2%}',
            'MA': '{:.2%}',
            'PA': '{:.2%}',
            'Hrs Period MA': '{:,.0f}',
            'Hrs Period PA': '{:,.0f}',
            'Target Hrs Variance': '{:,.0f}',
            'F300 SMR Operated': '{:,.0f}',
            'Variance F300': '{:,.0f}'
        })

        # if not period_name is None:
        #     m = dict(month=df_months, week=df_weeks)
        #     d_rng = tuple(m[period]().loc[period_name][['StartDate', 'EndDate']])

        if period == 'week':
            # fmt = f'%Y-%{week_letter}-%w'
            fmt = '%G-%V-%w'
            freq = 'W'
            # fmt_str = f'Week %{week_letter}'
            fmt_str = 'Week %V'
        else:
            fmt = '%Y-%m'
            freq = 'M'
            fmt_str = fmt

        f.set_self(vars())
コード例 #7
0
    def __init__(self, da=None, **kw):
        super().__init__(da=da, **kw)
        a, b, c, d, e = self.a, self.b, T('ComponentType'), self.d, T(
            'ComponentBench')

        life_achieved = Case().when(
            a.SMR == 0,
            None).else_(a.ComponentSMR - e.bench_smr).as_('Life Achieved')

        q = self.q \
            .inner_join(c).on_field('Floc') \
            .left_join(e).on(
                (a.Floc == e.floc) &
                ((b.Model == e.model) | (d.ModelBase == e.model_base) | (d.EquipClass == e.equip_class))) \
            .orderby(a.Unit, a.DateAdded, c.Modifier, a.GroupCO)

        f.set_self(vars())

        self.default_dtypes |= f.dtypes_dict(
            'Int64', ['Bench SMR', 'Life Achieved', 'Install SMR'])
コード例 #8
0
    def process_df(self, df):
        """Expand nested dicts of samples/flags to full columns"""

        # drop row number col
        if 'rn' in df.columns:
            df = df.drop(columns=['rn'])

        def expand_dict(df, col, suff):
            return df.join(
                pd.DataFrame(df.pop(col).apply(
                    json.loads).tolist()).add_suffix(suff))

        # save full df with flags for styling
        df = df \
            .pipe(expand_dict, col='test_results', suff='') \
            .pipe(expand_dict, col='test_flags', suff='_fg')

        # set iso/opc cols to Int64
        suffix = '_fg'
        int_cols = [
            col for col in df.columns if 'iso_' in col and not 'count' in col
        ]
        opc_cols = [col for col in df.columns if 'opc_' in col]
        int_cols.extend(opc_cols)
        int_cols.extend(
            ['cutting', 'sliding', 'fatigue', 'non_metal', 'fibers'])
        int_cols = [col for col in int_cols if not suffix in col]

        self.default_dtypes.update(**f.dtypes_dict('Int64', int_cols))

        # remove spaces between \ for iso and opc cols
        for col in ('opc', 'iso_count'):
            if col in df.columns:
                df[col] = df[col].str.replace(' ', '')

        flagged_cols = [col for col in df.columns if suffix in col]
        self.flagged_cols = flagged_cols

        self.df_flags = df.copy()
        return df.drop(columns=flagged_cols) \
            .replace('', pd.NA)
コード例 #9
0
    def __init__(self, **kw):
        super().__init__(**kw)
        limit_top = None

        self.default_dtypes |= f.dtypes_dict('Int64',
                                             ['unit_smr', 'component_smr'])

        a, b, c = self.select_table, T('UnitId'), T('EquipType')
        # cols = [a.star]
        cols = [
            a.unit, a.component_id, a.modifier, a.sample_date, a.unit_smr,
            a.oil_changed, a.sample_rank, a.test_results, a.test_flags
        ]

        q = Query.from_(a) \
            .left_join(b).on_field('Unit') \
            .left_join(c).on(b.Model == c.Model) \
            .orderby(a.unit, a.component_id, a.modifier) \
            .orderby(a.sample_date, order=Order.desc)

        f.set_self(vars())