evmtools-node
Version:
このライブラリは、プライムブレインズ社で利用している「進捗管理ツール(Excel)」ファイルを読み込み、 プロジェクトの進捗状況や要員別の作業量を可視化するためのライブラリです。
169 lines • 8.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toSales = exports.toCost = exports.単価単位調整 = exports.toProjectMemberInfo = exports.toMemberInfo = exports.toUnitInfo = exports.filter = exports.toGroupBy = void 0;
const resource_1 = require("./resource");
const common_1 = require("../../common");
const tidy_1 = require("@tidyjs/tidy");
const toGroupBy = (key, resourcePlans) => {
const unitAttrs = ['ユニットコード', 'ユニット名'];
const result = (0, tidy_1.tidy)(resourcePlans, (0, tidy_1.groupBy)(key, [
(0, tidy_1.summarize)({
ユニットコード: (instance) => unitAttrs.includes(key) ? instance[0].ユニットコード : '',
ユニット名: (instance) => (unitAttrs.includes(key) ? instance[0].ユニット名 : ''),
役職: (instance) => (['役職', '名前'].includes(key) ? instance[0].役職 : ''),
名前: (instance) => (['名前'].includes(key) ? instance[0].名前 : ''),
// 社内単価: (instance) => instance[0].社内単価,
社内単価: (group) => ['役職', '名前'].includes(key)
? group[0].社内単価
: (0, common_1.average)(group.map((instance) => instance.社内単価)),
プロジェクト単価: (group) => (0, common_1.average)(group.map((instance) => instance.プロジェクト単価)),
// ユニットコード: unitAttrs.includes(key) ? instance.ユニットコード[0] : '',
// ユニット名: unitAttrs.includes(key) ? instance.ユニット名[0] : '',
// 役職: ['役職', '名前'].includes(key) ? instance.役職[0] : '',
// 名前: ['名前'].includes(key) ? instance.名前[0] : '',
// 社内単価: ['役職', '名前'].includes(key)
// ? round(instance.社内単価[0], 0)
// : (average(instance.社内単価) as number),
// プロジェクト単価: average(instance.プロジェクト単価),
...monthlyAggregators(),
}),
]));
return result;
};
exports.toGroupBy = toGroupBy;
const filter = (condition, target) => {
const { ユニットコード, ユニット名, 役職, 名前, 社内単価, プロジェクト単価 } = condition;
return target.filter((info) =>
// (役職 != null ? 役職 === info.役職 : true) &&
// (名前 != null ? 名前 === info.名前 : true) &&
// (単価 != null ? 単価 === info.単価 : true)
(ユニットコード == null || ユニットコード === info.ユニットコード) &&
(ユニット名 == null || ユニット名 === info.ユニット名) &&
(役職 == null || 役職 === info.役職) &&
(名前 == null || 名前 === info.名前) &&
(社内単価 == null || 社内単価 === info.社内単価) &&
(プロジェクト単価 == null || プロジェクト単価 === info.プロジェクト単価));
};
exports.filter = filter;
/**
*
* ユニットコード、ユニット名を一覧する
* @param resourcePlans
* @returns
*/
const toUnitInfo = (resourcePlans) => {
const result = (0, tidy_1.tidy)(resourcePlans, (0, tidy_1.groupBy)('ユニットコード', [
(0, tidy_1.summarize)({
ユニットコード: (instance) => instance[0].ユニットコード,
ユニット名: (instance) => instance[0].ユニット名,
社内平均単価: (group) => (0, common_1.average)(group.map((instance) => instance.社内単価)),
プロジェクト平均単価: (group) => (0, common_1.average)(group.map((instance) => instance.プロジェクト単価)),
...monthlyAggregators(),
}),
]));
return result;
};
exports.toUnitInfo = toUnitInfo;
/**
*
* 社員情報を一覧する
* @param resourcePlans
* @returns
*/
const toMemberInfo = (resourcePlans) => {
const result = (0, tidy_1.tidy)(resourcePlans, (0, tidy_1.groupBy)('名前', [
(0, tidy_1.summarize)({
役職: (instance) => instance[0].役職,
名前: (instance) => instance[0].名前,
社内単価: (instance) => instance[0].社内単価,
}),
]));
return result;
};
exports.toMemberInfo = toMemberInfo;
// const monthlyAggregators = () => {
// return {
// '11月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['11月'] ?? 0)),
// '12月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['12月'] ?? 0)),
// '1月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['1月'] ?? 0)),
// '2月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['2月'] ?? 0)),
// '3月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['3月'] ?? 0)),
// '4月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['4月'] ?? 0)),
// '5月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['5月'] ?? 0)),
// '6月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['6月'] ?? 0)),
// '7月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['7月'] ?? 0)),
// '8月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['8月'] ?? 0)),
// '9月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['9月'] ?? 0)),
// '10月': (group: ResourcePlan[]) => sum(group.map((instance) => instance['10月'] ?? 0)),
// }
// }
function monthlyAggregators() {
return Object.fromEntries(resource_1.monthTypeStrs.map((month) => [
month,
(group) => (0, common_1.sum)(group.map((instance) => instance[month])),
]));
}
const toProjectMemberInfo = (resourcePlans) => {
const result = (0, tidy_1.tidy)(resourcePlans, (0, tidy_1.groupBy)(['ユニットコード', '名前'], [
(0, tidy_1.summarize)({
ユニットコード: (instances) => instances[0].ユニットコード,
ユニット名: (instances) => instances[0].ユニット名,
役職: (instances) => instances[0].役職,
名前: (instances) => instances[0].名前,
社内単価: (instances) => instances[0].社内単価,
プロジェクト単価: (group) => (0, common_1.average)(group.map((instance) => instance.プロジェクト単価)),
...monthlyAggregators(),
}),
]));
return result;
};
exports.toProjectMemberInfo = toProjectMemberInfo;
const 単価単位調整 = (instance, unit = 1000, scale = 4) => {
const calc = (resource) => {
return resource != null ? (0, common_1.round)(resource / unit, scale) : undefined;
};
return {
...instance,
社内単価: calc(instance.社内単価),
プロジェクト単価: calc(instance.プロジェクト単価),
};
};
exports.単価単位調整 = 単価単位調整;
/**
* @param instance
* @param price
* @returns
*/
const 月ごと単価 = (instance, price, scale = 4) => {
const calc = (resource) => {
return resource != null && price != null ? (0, common_1.round)(resource * price, scale) : undefined;
};
return {
'11月': calc(instance['11月']),
'12月': calc(instance['12月']),
'1月': calc(instance['1月']),
'2月': calc(instance['2月']),
'3月': calc(instance['3月']),
'4月': calc(instance['4月']),
'5月': calc(instance['5月']),
'6月': calc(instance['6月']),
'7月': calc(instance['7月']),
'8月': calc(instance['8月']),
'9月': calc(instance['9月']),
'10月': calc(instance['10月']),
};
};
const toCost = (instance) => ({
...instance,
...月ごと単価(instance, instance.社内単価),
});
exports.toCost = toCost;
const toSales = (instance) => ({
...instance,
...月ごと単価(instance, instance.プロジェクト単価),
});
exports.toSales = toSales;
// // このオブジェクトをつくって、マージする処理に変える
// // checkProjectみたいなメソッドで、エラーがあるかをチェックする。1超えた、足りないヒト、月売上げの集計とかいろいろ
// // 売上げ計算もしたい
//# sourceMappingURL=resourceUtils.js.map