RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/livechat/server/lib/analytics/dashboards.ts

Summary

Maintainability
D
3 days
Test Coverage

File dashboards.ts has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { OmnichannelAnalytics } from '@rocket.chat/core-services';
import type { IUser } from '@rocket.chat/core-typings';
import { LivechatRooms, Users, LivechatVisitors, LivechatAgentActivity } from '@rocket.chat/models';
import mem from 'mem';
import moment from 'moment';
Severity: Minor
Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts - About 4 hrs to fix

    Function findAllResponseTimeMetricsAsync has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    const findAllResponseTimeMetricsAsync = async ({
        start,
        end,
        departmentId = undefined,
    }: {
    Severity: Minor
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        (closed || []).forEach((department: { name: string; chats: number }) => {
            result[department.name] = {
                open: result[department.name] ? result[department.name].open : 0,
                closed: department.chats,
            };
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 1 other location - About 3 hrs to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 295..300

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 97.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        (closed || []).forEach((agent: { _id: string; chats: number }) => {
            result[agent._id] = {
                open: result[agent._id] ? result[agent._id].open : 0,
                closed: agent.chats,
            };
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 1 other location - About 3 hrs to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 340..345

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 97.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    const getAgentsProductivityMetricsAsync = async ({
        start,
        end,
        departmentId = undefined,
        user,
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 1 other location - About 1 hr to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 30..74

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 62.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    const getProductivityMetricsAsync = async ({
        start,
        end,
        departmentId = undefined,
        user,
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 1 other location - About 1 hr to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 76..145

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 62.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

        const sumOfServiceTime = averageOfServiceTime.departments.reduce(
            (
                acc: number,
                serviceTime: {
                    averageServiceTimeInSeconds: number;
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 65..68
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 170..181
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 182..193
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 194..205

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 57.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

        const sumOfPercentageOfAbandonedRooms = averageOfAbandonedRooms.departments.reduce(
            (
                acc: number,
                abandonedRoom: {
                    percentageOfAbandonedChats: number;
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 65..68
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 118..129
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 182..193
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 194..205

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 57.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

        const sumOfChatDurationTime = averageOfChatDurationTime.departments.reduce(
            (
                acc: number,
                chatDurationTime: {
                    averageChatDurationTimeInSeconds: number;
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 65..68
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 118..129
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 170..181
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 194..205

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 57.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

        const totalAbandonedRooms = abandonedRooms.departments.reduce(
            (
                acc: number,
                item: {
                    abandonedRooms: number;
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 65..68
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 118..129
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 170..181
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 182..193

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 57.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

        const sumOfWaitingTime = averageWaitingTime.departments.reduce((acc: number, serviceTime: { averageWaitingTimeInSeconds: number }) => {
            acc += serviceTime.averageWaitingTimeInSeconds;
            return acc;
        }, 0);
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 118..129
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 170..181
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 182..193
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 194..205

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 57.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const findAllChatMetricsByDepartmentAsync = async ({
        start,
        end,
        departmentId = undefined,
    }: {
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 4 other locations - About 50 mins to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 18..28
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 147..220
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 263..309
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 349..379

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const findAllResponseTimeMetricsAsync = async ({
        start,
        end,
        departmentId = undefined,
    }: {
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 4 other locations - About 50 mins to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 18..28
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 147..220
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 263..309
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 314..347

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const findAllChatsStatusAsync = async ({ start, end, departmentId = undefined }: { start: Date; end: Date; departmentId?: string }) => {
        if (!start || !end) {
            throw new Error('"start" and "end" must be provided');
        }
        return {
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 4 other locations - About 50 mins to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 147..220
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 263..309
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 314..347
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 349..379

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const getChatsMetricsAsync = async ({ start, end, departmentId = undefined }: { start: Date; end: Date; departmentId?: string }) => {
        if (!start || !end) {
            throw new Error('"start" and "end" must be provided');
        }
        const abandonedRooms = await findAllNumberOfAbandonedRoomsAsync({
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 4 other locations - About 50 mins to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 18..28
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 263..309
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 314..347
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 349..379

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const findAllChatMetricsByAgentAsync = async ({
        start,
        end,
        departmentId = undefined,
    }: {
    Severity: Major
    Found in apps/meteor/app/livechat/server/lib/analytics/dashboards.ts and 4 other locations - About 50 mins to fix
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 18..28
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 147..220
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 314..347
    apps/meteor/app/livechat/server/lib/analytics/dashboards.ts on lines 349..379

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status