From 89a8e2011e470a96c1458abdcd903612ec4146f6 Mon Sep 17 00:00:00 2001 From: coltoneshaw Date: Mon, 23 Aug 2021 12:48:02 -0400 Subject: [PATCH 1/3] Fixed bug with date selector --- .../Settings/Components/SaveSubmitButtons.tsx | 4 ++-- .../Settings/Components/StartDatePicker.tsx | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/Pages/Settings/Components/SaveSubmitButtons.tsx b/src/app/Pages/Settings/Components/SaveSubmitButtons.tsx index f18921e9..06c865d9 100644 --- a/src/app/Pages/Settings/Components/SaveSubmitButtons.tsx +++ b/src/app/Pages/Settings/Components/SaveSubmitButtons.tsx @@ -14,7 +14,7 @@ const SaveSubmitButtons = ({setOpen}: SubmitButtons) => { const { reset, setConfigBulk } = configState const dataState = useGlobalData() - const {actions: {updateAllData}} = dataState + const {actions: { updateAllData }, data: { isSyncing}} = dataState const [ loader, setLoaderIcon ] = useState(false) const callback = () => setOpen(true) @@ -55,7 +55,7 @@ const SaveSubmitButtons = ({setOpen}: SubmitButtons) => { }} disableElevation > - {( loader) ? <> Syncing... : "Save"} + {( isSyncing) ? <> Syncing... : "Save"} ) diff --git a/src/app/Pages/Settings/Components/StartDatePicker.tsx b/src/app/Pages/Settings/Components/StartDatePicker.tsx index d2165e0c..208bb34e 100644 --- a/src/app/Pages/Settings/Components/StartDatePicker.tsx +++ b/src/app/Pages/Settings/Components/StartDatePicker.tsx @@ -1,4 +1,4 @@ -import { getTime, parseISO, formatISO } from 'date-fns' +import { getTime, parseISO, formatISO, isValid } from 'date-fns' import React, { useContext, useState, useEffect, forwardRef } from 'react'; import DateFnsUtils from '@date-io/date-fns'; @@ -20,17 +20,20 @@ export default function StartDatePicker() { const [localDate, setLocalDate] = useState(); const handleDateChange = (date: any) => { - setLocalDate(date) + if (date != undefined && isValid(new Date(date))) { + setLocalDate(date) + + // getting the shortform utc date, stripping and converting to ISO + const dateString = formatISO(date, { representation: 'date' }) + const utcDate = dateString + 'T00:00:00Z' + updateDate(getTime(parseISO(utcDate))); + } - // getting the shortform utc date, stripping and converting to ISO - const dateString = formatISO(date, { representation: 'date' }) - const utcDate = dateString + 'T00:00:00Z' - updateDate(getTime(parseISO(utcDate))); }; // converting the date into a ISO date and storing it. useEffect(() => { - const adjustedTime = date + ( (new Date()).getTimezoneOffset() * 60000 ) + const adjustedTime = date + ((new Date()).getTimezoneOffset() * 60000) const dateString = new Date(adjustedTime).toUTCString() console.log(dateString) setLocalDate(dateString) From c68532df34ed0531bb2e48afc5042caf5f2a2011 Mon Sep 17 00:00:00 2001 From: coltoneshaw Date: Mon, 23 Aug 2021 12:48:33 -0400 Subject: [PATCH 2/3] Fixed bug with avg deal hours, added total deals / hours as a metric now --- .../Charts/DataCards/metrics/AverageDealHours.tsx | 12 +++++++++--- src/app/Context/DataContext.tsx | 3 ++- src/app/Features/3Commas/3Commas.ts | 14 ++++++++++---- src/app/Pages/Stats/Stats.tsx | 4 ++-- src/descriptions.ts | 3 ++- src/types/3Commas.ts | 9 +++++++-- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/app/Components/Charts/DataCards/metrics/AverageDealHours.tsx b/src/app/Components/Charts/DataCards/metrics/AverageDealHours.tsx index 56fb404b..e1730fe3 100644 --- a/src/app/Components/Charts/DataCards/metrics/AverageDealHours.tsx +++ b/src/app/Components/Charts/DataCards/metrics/AverageDealHours.tsx @@ -6,17 +6,23 @@ import { parseNumber } from "@/utils/number_formatting" interface Type_Card { - metric: number + metric: number, + additionalData: { + totalClosedDeals: number + totalDealHours: number + } } /** * * @param metric - accepts the averageDailyProfit metric from the global data store. */ -const Card_AverageDealHours = ({metric}:Type_Card) => { +const Card_AverageDealHours = ({metric, additionalData}:Type_Card) => { + + const {totalClosedDeals, totalDealHours} = additionalData const title = "Avg. Deal Hours" - const message = descriptions.metrics.averageDealHours + const message = descriptions.calculations.averageDealHours( totalClosedDeals, totalDealHours) const key = title.replace(/\s/g, '') return ( diff --git a/src/app/Context/DataContext.tsx b/src/app/Context/DataContext.tsx index 2ad2cfe7..e6350951 100644 --- a/src/app/Context/DataContext.tsx +++ b/src/app/Context/DataContext.tsx @@ -52,7 +52,8 @@ const defaultMetrics = { position: 0, on_orders: 0, totalInDeals: 0, - reservedFundsTotal: 0 + reservedFundsTotal: 0, + totalClosedDeals: 0 } diff --git a/src/app/Features/3Commas/3Commas.ts b/src/app/Features/3Commas/3Commas.ts index 29048cb2..fe9790af 100644 --- a/src/app/Features/3Commas/3Commas.ts +++ b/src/app/Features/3Commas/3Commas.ts @@ -63,7 +63,8 @@ const fetchDealDataFunction = async () => { SELECT substr(closed_at, 0, 11) as closed_at_str, sum(final_profit) as final_profit, - sum(deal_hours) as deal_hours + sum(deal_hours) as deal_hours, + count(id) as total_deals FROM deals WHERE @@ -106,21 +107,26 @@ const fetchDealDataFunction = async () => { profitArray.push({ utc_date: day.closed_at_str, profit: day.final_profit, - runningSum: runningSum + runningSum: runningSum, + total_deals: day.total_deals }) }) const totalProfit = (profitArray.length > 0) ? +profitArray[profitArray.length - 1].runningSum : 0 const averageDailyProfit = (profitArray.length > 0) ? totalProfit / (profitArray.length + 1) : 0; - const averageDealHours = (profitArray.length > 0) ? totalDealHours / (profitArray.length + 1) : 0; + const totalClosedDeals = (profitArray.length > 0) ? profitArray.map(day => day.total_deals).reduce( (sum:number, total_deals: number) => sum + total_deals) : 0; + const averageDealHours = (profitArray.length > 0) ? totalDealHours / totalClosedDeals : 0; + console.log({totalDealHours, profitArray, totalClosedDeals}) return { profitData: profitArray, metrics: { totalProfit, averageDailyProfit, - averageDealHours + averageDealHours, + totalClosedDeals, + totalDealHours } } diff --git a/src/app/Pages/Stats/Stats.tsx b/src/app/Pages/Stats/Stats.tsx index f8a29139..28d5b82f 100644 --- a/src/app/Pages/Stats/Stats.tsx +++ b/src/app/Pages/Stats/Stats.tsx @@ -42,7 +42,7 @@ const StatsPage = () => { const { config, state: { reservedFunds } } = configState const state = useGlobalData() const { data: { metricsData, isSyncing }, actions: { updateAllData } } = state - const { activeDealCount, totalInDeals, maxRisk, totalBankroll, position, on_orders, totalProfit, totalBoughtVolume, reservedFundsTotal, maxRiskPercent, totalDeals, boughtVolume, totalProfit_perf, averageDailyProfit, averageDealHours } = metricsData + const { activeDealCount, totalInDeals, maxRisk, totalBankroll, position, on_orders, totalProfit, totalBoughtVolume, reservedFundsTotal, maxRiskPercent, totalDeals, boughtVolume, totalProfit_perf, averageDailyProfit, averageDealHours, totalClosedDeals, totalDealHours } = metricsData const [currentView, changeView] = useState('summary-stats') const date: undefined | number = dotProp.get(config, 'statSettings.startDate') @@ -97,7 +97,7 @@ const StatsPage = () => { - + ) } } diff --git a/src/descriptions.ts b/src/descriptions.ts index a8985409..c0213e51 100644 --- a/src/descriptions.ts +++ b/src/descriptions.ts @@ -11,13 +11,14 @@ const descriptions = { totalInDeals: ( on_orders:number , totalBoughtVolume:number ) => ` adds together the total amount of funds that you have within a deal. This consists of funds on order of ${parseNumber(on_orders)} and total bought volume of your deals of ${parseNumber(totalBoughtVolume)}.`, totalProfit: ` is the sum of all the profit you've made within the filtered time period.`, totalRoi: ( totalProfit_perf:number , boughtVolume:number ) => ` calculates the total return on your investment based on the bought volume of ${parseNumber(boughtVolume)} divided by the total profit of ${parseNumber(totalProfit_perf)}`, + averageDealHours: (totalClosedDeals:number , totalDealHours:number ) => ` is the average amount of time it takes for your deals to close. You have ${parseNumber(totalClosedDeals)} deals and ${parseNumber(totalDealHours)} hours in those deals.`, + }, metrics: { totalBoughtVolume: ` is the total that your bots have put into a deal.`, totalDeals: ` is the total amount of deals closed during the filtered period.`, averageDailyProfit: ` is the amount of total profit you've made divided by the total number of days included in your filter.`, - averageDealHours: ` is the total average amount of time it takes for your deals to close.`, todaysProfit: ` is the sum of the profit you've made in UTC today. Note this does not always reset at midnight, depending on your timezone`, activeDealReserves: ` is the sum of all your deals current profit. This number can be postive / negative based on where all your deals are currently.` } diff --git a/src/types/3Commas.ts b/src/types/3Commas.ts index a0f64616..2332cab1 100644 --- a/src/types/3Commas.ts +++ b/src/types/3Commas.ts @@ -44,12 +44,15 @@ export interface Type_Query_DealData { closed_at: string id: number deal_hours: number, + total_deals: number } export type Type_Profit = { utc_date: string profit: number runningSum: number + total_deals: number + } @@ -228,10 +231,12 @@ export interface Type_MetricData { bankrollAvailable: number totalBankroll: number position: number - on_orders: number + on_orders: number // total number of funds in an exchange order that's not filled totalInDeals: number availableBankroll: number, - reservedFundsTotal: number + reservedFundsTotal: number, + totalClosedDeals: number, // total number of deals closed for the filtered time + totalDealHours: number // this is the total hours in deals you have for the filtered time } export interface Type_MarketOrders { From 2ec2779857319a9285fefc17c36e45024bb23ce0 Mon Sep 17 00:00:00 2001 From: coltoneshaw Date: Mon, 23 Aug 2021 12:51:41 -0400 Subject: [PATCH 3/3] bumped version, added changelog --- CHANGELOG.md | 9 +++++++++ package.json | 2 +- src/app/Features/Changelog/changelogText.tsx | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44839902..47a522ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v0.2.1 + +## Enhancements +- Added a calculated tooltip to avg deal hours + +## Bug +- Manually typing into the date selector would crash the application. +- Avg Deal hours was incorrectly averaging the sum by date instead of by deal. + # v0.2.0 ## Enhancements diff --git a/package.json b/package.json index c215f753..cc6ac187 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "3c-portfolio-manager", "productName": "3C Portfolio Manager", - "version": "0.1.1", + "version": "0.2.1", "description": "An application to manage your 3Commas portfolio.", "private": true, "main": "./dist/main.js", diff --git a/src/app/Features/Changelog/changelogText.tsx b/src/app/Features/Changelog/changelogText.tsx index d168ca18..f346475b 100644 --- a/src/app/Features/Changelog/changelogText.tsx +++ b/src/app/Features/Changelog/changelogText.tsx @@ -1,5 +1,5 @@ -const mostRecent = '0.1.1' +const mostRecent = '0.2.1' const versionInformation = [ @@ -155,6 +155,17 @@ const versionInformation = [ 'Added additional filters to Bot / Pair performance charts' ] }, + { + version: '0.2.1', + enhancements: [ + 'Added a calculated tooltip to avg deal hours', + ], + bugs: [ + 'Manually typing into the date selector would crash the application.', + 'Avg Deal hours was incorrectly averaging the sum by date instead of by deal.' + ], + new: [] + }, ] export {