Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.0 kB
3
Indexable
Never
[
  {
    $match: {
      companyId: "5fbea8d67e3d559250852e78",
    },
  },
  {
    $lookup: {
      from: "users",
      localField: "user",
      foreignField: "_id",
      as: "userdetail",
    },
  },
  {
    $project: {
      timestamp: "$timestamp",
      date: {
        $dateToString: {
          timezone: "Asia/Calcutta",
          date: {
            $add: [new Date(0), "$timestamp"],
          },
        },
      },
      lastFromCurrent: {
        $dateToString: {
          timezone: "Asia/Calcutta",
          date: {
            $add: [new Date(0), 1678300200000],
          },
        },
      },
      companyId: "$companyId",
      sessionId: "$sessionId",
      sessionName: "$sessionName",
      mentionedResponse: "$mentionedResponse",
      frameworkId: "$framework.id",
      frameworkName: "$framework.name",
      user: "$user",
      userDetail: "$userdetail",
      objectionsFound: "$objectionsFound",
      framework: "$framework",
      conversation: "$logs",
      disposition: "$disposition",
      frameworkSuccessPercent: {
        $round: [
          {
            $multiply: [
              {
                $divide: [
                  {
                    $ifNull: [
                      "$framework.success",
                      0,
                    ],
                  },
                  {
                    $cond: {
                      if: {
                        $eq: [
                          {
                            $sum: {
                              $size:
                                "$framework.steps",
                            },
                          },
                          0,
                        ],
                      },
                      then: 1,
                      else: {
                        $sum: {
                          $size:
                            "$framework.steps",
                        },
                      },
                    },
                  },
                ],
              },
              100,
            ],
          },
        ],
      },
      logs: "$logs",
      repTalkPercen: {
        $round: [
          {
            $cond: {
              if: {
                $eq: [
                  {
                    $sum: {
                      $size: "$logs",
                    },
                  },
                  0,
                ],
              },
              then: 0,
              else: {
                $round: [
                  {
                    $multiply: [
                      {
                        $divide: [
                          {
                            $ifNull: [
                              {
                                $sum: {
                                  $size: {
                                    $filter: {
                                      input:
                                        "$logs",
                                      as: "logs",
                                      cond: {
                                        $eq: [
                                          "$$logs.voiceFrom",
                                          "rep",
                                        ],
                                      },
                                    },
                                  },
                                },
                              },
                              0,
                            ],
                          },
                          {
                            $sum: {
                              $size: "$logs",
                            },
                          },
                        ],
                      },
                      100,
                    ],
                  },
                ],
              },
            },
          },
        ],
      },
      duration: {
        $divide: [
          {
            $subtract: [
              "$eTimestamp",
              "$timestamp",
            ],
          },
          1000,
        ],
      },
    },
  },
  {
    $match: {
      timestamp: {
        $gt: 1678127400000,
        $lt: 1678472999000,
      },
    },
  },
  {
    $addFields: {
      lastFromCurrentDate: {
        $dateFromString: {
          dateString: "$lastFromCurrent",
        },
      },
      callDate: {
        $dateFromString: {
          dateString: "$date",
        },
      },
    },
  },
  {
    $addFields: {
      isNew: {
        $cond: [
          {
            $gte: [
              "$callDate",
              "$lastFromCurrentDate",
            ],
          },
          "current",
          "prev",
        ],
      },
    },
  },
  {
    $project: {
      userDetail: false,
      objectionsFound: false,
      sessionName: false,
      frameworkName: false,
      user: false,
      framework: false,
      frameworkSuccessPercent: false,
      logs: false,
    },
  },
  {
    $sort: {
      _id: -1,
    },
  },
]