Reconfigured smart scheduling to use buckets instead of load.

This commit is contained in:
Patrick Fic
2020-10-08 15:42:04 -07:00
parent 020bec3fa2
commit 5f73c879d0
16 changed files with 405 additions and 32 deletions

View File

@@ -1,15 +1,18 @@
import { Popover } from "antd"; import { Popover } from "antd";
import React from "react"; import React, { useMemo } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { import {
PolarAngleAxis, PolarAngleAxis,
PolarGrid, PolarGrid,
PolarRadiusAxis, PolarRadiusAxis,
Radar, Radar,
Legend,
RadarChart, RadarChart,
Tooltip,
} from "recharts"; } from "recharts";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors";
import { RadarChartOutlined } from "@ant-design/icons";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -21,44 +24,54 @@ const mapDispatchToProps = (dispatch) => ({
export function ScheduleCalendarHeaderGraph({ bodyshop, loadData }) { export function ScheduleCalendarHeaderGraph({ bodyshop, loadData }) {
const { ssbuckets } = bodyshop; const { ssbuckets } = bodyshop;
const data = Object.keys(loadData.expectedLoad).map((key) => { const data = useMemo(() => {
const metadataBucket = ssbuckets.filter((b) => b.id === key)[0]; return Object.keys(loadData.expectedLoad).map((key) => {
const metadataBucket = ssbuckets.filter((b) => b.id === key)[0];
return { return {
bucket: loadData.expectedLoad[key].label, bucket: loadData.expectedLoad[key].label,
current: loadData.expectedLoad[key].count, current: loadData.expectedLoad[key].count,
target: metadataBucket && metadataBucket.target, target: metadataBucket && metadataBucket.target,
}; };
}); });
}, [loadData, ssbuckets]);
//d console.log("data", data);
const popContent = ( const popContent = (
<div> <div>
<RadarChart <RadarChart
cx={300} // cx={300}
cy={250} // cy={250}
outerRadius={150} // outerRadius={150}
width={600} width={800}
height={500} height={600}
data={data} data={data}
> >
<PolarGrid /> <PolarGrid />
<PolarAngleAxis dataKey="bucket" /> <PolarAngleAxis dataKey="bucket" />
<PolarRadiusAxis /> <PolarRadiusAxis angle={90} />
<Radar
name="Ideal Load"
dataKey="target"
stroke="darkgreen"
fill="whitr"
fillOpacity={0}
/>
<Radar <Radar
name="Current" name="Current"
dataKey="current" dataKey="current"
stroke="#8884d8" stroke="dodgerblue"
fill="#8884d8" fill="dodgerblue"
fillOpacity={0.6} fillOpacity={0.6}
/> />
<Tooltip />
<Legend />
</RadarChart> </RadarChart>
</div> </div>
); );
return ( return (
<Popover trigger="hover" placement="bottom" content={popContent}> <Popover trigger="hover" placement="bottom" content={popContent}>
G <RadarChartOutlined />
</Popover> </Popover>
); );
} }

View File

@@ -70,12 +70,20 @@ export function ScheduleCalendarWrapperComponent({
search.view = view; search.view = view;
history.push({ search: queryString.stringify(search) }); history.push({ search: queryString.stringify(search) });
}} }}
step={15} step={30}
timeslots={1} timeslots={1}
showMultiDayTimes showMultiDayTimes
localizer={localizer} localizer={localizer}
min={new Date("2020-01-01T06:00:00")} //TODO Read from business settings. min={
max={new Date("2020-01-01T20:00:00")} bodyshop.schedule_start_time
? new Date(bodyshop.schedule_start_time)
: new Date("2020-01-01T06:00:00")
} //TODO Read from business settings.
max={
bodyshop.schedule_end_time
? new Date(bodyshop.schedule_end_time)
: new Date("2020-01-01T20:00:00")
}
eventPropGetter={handleEventPropStyles} eventPropGetter={handleEventPropStyles}
components={{ components={{
event: (e) => Event({ event: e.event, refetch: refetch }), event: (e) => Event({ event: e.event, refetch: refetch }),

View File

@@ -8,7 +8,7 @@ import AlertComponent from "../alert/alert.component";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { logImEXEvent } from "../../firebase/firebase.utils"; import { logImEXEvent } from "../../firebase/firebase.utils";
import FormsFieldChanged from "../form-fields-changed-alert/form-fields-changed-alert.component"; import FormsFieldChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
import moment from "moment";
export default function ShopInfoContainer() { export default function ShopInfoContainer() {
const [form] = Form.useForm(); const [form] = Form.useForm();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -49,7 +49,17 @@ export default function ShopInfoContainer() {
layout="vertical" layout="vertical"
autoComplete="new-password" autoComplete="new-password"
onFinish={handleFinish} onFinish={handleFinish}
initialValues={data ? data.bodyshops[0] : null} initialValues={
data
? {
...data.bodyshops[0],
schedule_start_time: moment(
data.bodyshops[0].schedule_start_time
),
schedule_end_time: moment(data.bodyshops[0].schedule_end_time),
}
: null
}
> >
<FormsFieldChanged form={form} /> <FormsFieldChanged form={form} />
<ShopInfoComponent form={form} saveLoading={saveLoading} /> <ShopInfoComponent form={form} saveLoading={saveLoading} />

View File

@@ -1,5 +1,14 @@
import { DeleteFilled } from "@ant-design/icons"; import { DeleteFilled } from "@ant-design/icons";
import { Button, Col, Form, Input, InputNumber, Row, Select } from "antd"; import {
Button,
Col,
Form,
Input,
InputNumber,
Row,
Select,
TimePicker,
} from "antd";
import React from "react"; import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import ColorpickerFormItemComponent from "../form-items-formatted/colorpicker-form-item.component"; import ColorpickerFormItemComponent from "../form-items-formatted/colorpicker-form-item.component";
@@ -11,6 +20,30 @@ export default function ShopInfoSchedulingComponent({ form }) {
return ( return (
<div> <div>
<Form.Item
label={t("bodyshop.fields.schedule_start_time")}
name={"schedule_start_time"}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<TimePicker showSecond={false} />
</Form.Item>
<Form.Item
label={t("bodyshop.fields.schedule_end_time")}
name={"schedule_end_time"}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<TimePicker showSecond={false} />
</Form.Item>
<strong>{t("bodyshop.labels.orderstatuses")}</strong> <strong>{t("bodyshop.labels.orderstatuses")}</strong>
<Row> <Row>
<Col span={24}> <Col span={24}>

View File

@@ -72,6 +72,8 @@ export const QUERY_BODYSHOP = gql`
target_touchtime target_touchtime
appt_colors appt_colors
appt_alt_transport appt_alt_transport
schedule_start_time
schedule_end_time
employees { employees {
id id
first_name first_name
@@ -142,6 +144,8 @@ export const UPDATE_SHOP = gql`
target_touchtime target_touchtime
appt_colors appt_colors
appt_alt_transport appt_alt_transport
schedule_start_time
schedule_end_time
employees { employees {
id id
first_name first_name

View File

@@ -114,7 +114,6 @@ export function* calculateScheduleLoad({ payload: end }) {
load[current].jobsOut || [] load[current].jobsOut || []
); );
} }
console.log(load);
} }
yield put(scheduleLoadSuccess(load)); yield put(scheduleLoadSuccess(load));

View File

@@ -1,9 +1,11 @@
import _ from "lodash";
export const CheckJobBucket = (buckets, job) => { export const CheckJobBucket = (buckets, job) => {
const jobHours = const jobHours =
job.labhrs.aggregate.sum.mod_lb_hrs + job.larhrs.aggregate.sum.mod_lb_hrs; job.labhrs.aggregate.sum.mod_lb_hrs + job.larhrs.aggregate.sum.mod_lb_hrs;
const matchingBucket = buckets.filter( const matchingBucket = buckets.filter((b) =>
(b) => b.gte <= jobHours && b.lt > jobHours b.gte <= jobHours && b.lt ? b.lt > jobHours : true
); );
return matchingBucket[0] && matchingBucket[0].id; return matchingBucket[0] && matchingBucket[0].id;
@@ -11,7 +13,7 @@ export const CheckJobBucket = (buckets, job) => {
export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => { export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
//Add the jobs coming //Add the jobs coming
const newLoad = { ...currentLoad }; const newLoad = _.cloneDeep(currentLoad);
jobsIn.forEach((job) => { jobsIn.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job); const bucketId = CheckJobBucket(buckets, job);
if (bucketId) { if (bucketId) {
@@ -30,13 +32,11 @@ export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
newLoad[bucketId].count = newLoad[bucketId].count - 1; newLoad[bucketId].count = newLoad[bucketId].count - 1;
} else { } else {
console.log( console.log(
"[Util Arr Job]Uh oh, this job doesn't fit in a bucket!", "[Util Out Job]Uh oh, this job doesn't fit in a bucket!",
job job
); );
} }
}); });
console.log("newLoad", newLoad);
return newLoad; return newLoad;
}; };

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "schedule_start_time";
type: run_sql

View File

@@ -0,0 +1,6 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "schedule_start_time" timestamptz
NULL;
type: run_sql

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "schedule_end_time";
type: run_sql

View File

@@ -0,0 +1,6 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "schedule_end_time" timestamptz
NULL;
type: run_sql

View File

@@ -0,0 +1,72 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- accountingconfig
- address1
- address2
- appt_alt_transport
- appt_colors
- appt_length
- bill_tax_rates
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- messagingservicesid
- phone
- prodtargethrs
- production_config
- region_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- stripe_acct_id
- target_touchtime
- template_header
- textid
- updated_at
- zip_post
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,74 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- accountingconfig
- address1
- address2
- appt_alt_transport
- appt_colors
- appt_length
- bill_tax_rates
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- messagingservicesid
- phone
- prodtargethrs
- production_config
- region_config
- schedule_end_time
- schedule_start_time
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- stripe_acct_id
- target_touchtime
- template_header
- textid
- updated_at
- zip_post
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,66 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- accountingconfig
- address1
- address2
- appt_alt_transport
- appt_colors
- appt_length
- bill_tax_rates
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- phone
- prodtargethrs
- production_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- target_touchtime
- updated_at
- zip_post
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission

View File

@@ -0,0 +1,68 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- accountingconfig
- address1
- address2
- appt_alt_transport
- appt_colors
- appt_length
- bill_tax_rates
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- phone
- prodtargethrs
- production_config
- schedule_end_time
- schedule_start_time
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- target_touchtime
- updated_at
- zip_post
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission

View File

@@ -734,6 +734,8 @@ tables:
- prodtargethrs - prodtargethrs
- production_config - production_config
- region_config - region_config
- schedule_end_time
- schedule_start_time
- scoreboard_target - scoreboard_target
- shopname - shopname
- shoprates - shoprates
@@ -792,6 +794,8 @@ tables:
- phone - phone
- prodtargethrs - prodtargethrs
- production_config - production_config
- schedule_end_time
- schedule_start_time
- scoreboard_target - scoreboard_target
- shopname - shopname
- shoprates - shoprates