Code Duplication    Length = 18-20 lines in 2 locations

chezbetty/views_data.py 2 locations

@@ 161-180 (lines=20) @@
158
def admin_data_period(num_days, metric, period):
159
    return admin_data_period_range(get_start(num_days), get_end(), metric, period)
160
161
def admin_data_highcharts_period(metric, period):
162
    start = get_start(0)
163
    end = get_end()
164
    if metric == 'items':
165
        data = PurchaseLineItem.quantity_by_period(period, start=ftz(start), end=ftz(end))
166
        return datetime_to_timestamps(data)
167
    elif metric == 'sales':
168
        data = PurchaseLineItem.virtual_revenue_by_period(period, start=ftz(start), end=ftz(end))
169
        return datetime_to_timestamps(data, float)
170
    elif metric == 'deposits':
171
        data = Deposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
172
        return datetime_to_timestamps(data, float)
173
    elif metric == 'deposits_cash':
174
        data = CashDeposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
175
        return datetime_to_timestamps(data, float)
176
    elif metric == 'deposits_btc':
177
        data = BTCDeposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
178
        return datetime_to_timestamps(data, float)
179
    else:
180
        raise(InvalidMetric(metric))
181
182
183
###
@@ 138-155 (lines=18) @@
135
# end:    datetime.datetime that all data must be before
136
# metric: 'items', 'sales', or 'deposits'
137
# period: 'day', 'month', or 'year'
138
def admin_data_period_range(start, end, metric, period):
139
    if metric == 'items':
140
        data = PurchaseLineItem.quantity_by_period(period, start=ftz(start), end=ftz(end))
141
        return zip(create_x_y_from_group(data, start, end, period))
142
    elif metric == 'sales':
143
        data = PurchaseLineItem.virtual_revenue_by_period(period, start=ftz(start), end=ftz(end))
144
        return zip(create_x_y_from_group(data, start, end, period, float, 0.0))
145
    elif metric == 'deposits':
146
        data = Deposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
147
        return zip(create_x_y_from_group(data,  start, end, period, float, 0.0))
148
    elif metric == 'deposits_cash':
149
        data = CashDeposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
150
        return zip(create_x_y_from_group(data,  start, end, period, float, 0.0))
151
    elif metric == 'deposits_btc':
152
        data = BTCDeposit.deposits_by_period('day', start=ftz(start), end=ftz(end))
153
        return zip(create_x_y_from_group(data,  start, end, period, float, 0.0))
154
    else:
155
        raise(InvalidMetric(metric))
156
157
158
def admin_data_period(num_days, metric, period):