mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 06:21:37 +01:00
chore: more things
This commit is contained in:
parent
dce5795fa8
commit
bf69ff995b
2 changed files with 40 additions and 32 deletions
|
@ -6,12 +6,16 @@ import { subHours, subDays } from "date-fns";
|
||||||
import { countArray } from "./Helpers";
|
import { countArray } from "./Helpers";
|
||||||
import { ForwardCompleteProps } from "./ForwardReport.interface";
|
import { ForwardCompleteProps } from "./ForwardReport.interface";
|
||||||
import { ForwardChannelsType } from "../../../schemaTypes/query/report/ForwardChannels";
|
import { ForwardChannelsType } from "../../../schemaTypes/query/report/ForwardChannels";
|
||||||
|
import { sortBy } from "underscore";
|
||||||
|
|
||||||
export const getForwardChannelsReport = {
|
export const getForwardChannelsReport = {
|
||||||
type: ForwardChannelsType,
|
type: ForwardChannelsType,
|
||||||
args: {
|
args: {
|
||||||
time: {
|
time: {
|
||||||
type: GraphQLString
|
type: GraphQLString
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
type: GraphQLString
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
|
@ -46,9 +50,16 @@ export const getForwardChannelsReport = {
|
||||||
const incomingCount = countArray(forwardsList.forwards, true);
|
const incomingCount = countArray(forwardsList.forwards, true);
|
||||||
const outgoingCount = countArray(forwardsList.forwards, false);
|
const outgoingCount = countArray(forwardsList.forwards, false);
|
||||||
|
|
||||||
|
const sortedInCount = sortBy(incomingCount, params.order)
|
||||||
|
.reverse()
|
||||||
|
.slice(0, 5);
|
||||||
|
const sortedOutCount = sortBy(outgoingCount, params.order)
|
||||||
|
.reverse()
|
||||||
|
.slice(0, 5);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
incoming: JSON.stringify(incomingCount),
|
incoming: JSON.stringify(sortedInCount),
|
||||||
outgoing: JSON.stringify(outgoingCount)
|
outgoing: JSON.stringify(sortedOutCount)
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting forward channel report: %o", error);
|
logger.error("Error getting forward channel report: %o", error);
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
import { reduce, sortBy } from "underscore";
|
import { reduce, groupBy } from "underscore";
|
||||||
import {
|
import {
|
||||||
ForwardProps,
|
ForwardProps,
|
||||||
ReduceObjectProps,
|
ReduceObjectProps,
|
||||||
FinalProps,
|
ListProps
|
||||||
FinalList,
|
|
||||||
ListProps,
|
|
||||||
CountProps,
|
|
||||||
ChannelCounts
|
|
||||||
} from "./ForwardReport.interface";
|
} from "./ForwardReport.interface";
|
||||||
|
|
||||||
export const reduceForwardArray = (list: ListProps): FinalList => {
|
export const reduceForwardArray = (list: ListProps) => {
|
||||||
let reducedOrder: FinalList = {};
|
const reducedOrder = [];
|
||||||
for (const key in list) {
|
for (const key in list) {
|
||||||
if (list.hasOwnProperty(key)) {
|
if (list.hasOwnProperty(key)) {
|
||||||
const element: ForwardProps[] = list[key];
|
const element: ForwardProps[] = list[key];
|
||||||
|
@ -20,39 +16,40 @@ export const reduceForwardArray = (list: ListProps): FinalList => {
|
||||||
tokens: a.tokens + b.tokens
|
tokens: a.tokens + b.tokens
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
reducedOrder[key] = {
|
reducedOrder.push({
|
||||||
|
period: parseInt(key),
|
||||||
amount: element.length,
|
amount: element.length,
|
||||||
...reducedArray
|
...reducedArray
|
||||||
} as FinalProps;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return reducedOrder;
|
return reducedOrder;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const countArray = (
|
export const countArray = (list: ForwardProps[], type: boolean) => {
|
||||||
list: ForwardProps[],
|
const inOrOut = type ? "incoming_channel" : "outgoing_channel";
|
||||||
type: boolean
|
const grouped = groupBy(list, inOrOut);
|
||||||
): ChannelCounts[] => {
|
|
||||||
const count: CountProps = {};
|
|
||||||
list
|
|
||||||
.map(item => {
|
|
||||||
return type ? item.incoming_channel : item.outgoing_channel;
|
|
||||||
})
|
|
||||||
.forEach(channel => {
|
|
||||||
count[channel] = (count[channel] || 0) + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const mapped: ChannelCounts[] = [];
|
const channelInfo = [];
|
||||||
for (const key in count) {
|
for (const key in grouped) {
|
||||||
if (count.hasOwnProperty(key)) {
|
if (grouped.hasOwnProperty(key)) {
|
||||||
const element = count[key];
|
const element = grouped[key];
|
||||||
mapped.push({
|
|
||||||
|
const fee = element.map(forward => forward.fee).reduce((p, c) => p + c);
|
||||||
|
|
||||||
|
const tokens = element
|
||||||
|
.map(forward => forward.tokens)
|
||||||
|
.reduce((p, c) => p + c);
|
||||||
|
|
||||||
|
channelInfo.push({
|
||||||
name: key,
|
name: key,
|
||||||
count: element
|
amount: element.length,
|
||||||
|
fee: fee,
|
||||||
|
tokens: tokens
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortBy(mapped, "count");
|
|
||||||
return mapped;
|
return channelInfo;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue