<commit_before>package drt.client.components

import drt.client.logger.{Logger, LoggerFactory}
import drt.client.modules.GoogleEventTracker
import drt.client.services.JSDateConversions.SDate
import drt.client.services.SPACircuit
import drt.shared.CrunchApi.MillisSinceEpoch
import drt.shared.{FeedSourceStatuses, FeedStatusFailure, FeedStatusSuccess}
import japgolly.scalajs.react.vdom.html_<^._
import japgolly.scalajs.react.{Callback, ScalaComponent}

object StatusPage {

  val log: Logger = LoggerFactory.getLogger(getClass.getName)

  case class Props()

  val component = ScalaComponent.builder[Props]("StatusPage")
    .render_P { _ =>

      val feedStatusesRCP = SPACircuit.connect(_.feedStatuses)

      feedStatusesRCP { feedStatusesMP =>
        val feedStatusesPot = feedStatusesMP()

        <.div(
          <.h2("Feeds status"),
          feedStatusesPot.render((allFeedStatuses: Seq[FeedSourceStatuses]) => {
            val isLiveFeedAvailable = allFeedStatuses.count(_.feedSource.name == "Port Live") > 0
            allFeedStatuses.map(feed => {
              <.div(^.className := s"feed-status ${feed.feedStatuses.ragStatus(SDate.now().millisSinceEpoch)}",
                <.h3(feed.feedSource.name),
                <.div(^.className := s"feed-status-description", <.p(feed.feedSource.description(isLiveFeedAvailable))),
                {
                  val times = Seq(
                    (("Updated", "When we last received new data"), feed.feedStatuses.lastUpdatesAt),
                    (("Checked", "When we last checked for new data"), feed.feedStatuses.lastSuccessAt),
                    (("Failed", "When we last experienced a failure with the feed"), feed.feedStatuses.lastFailureAt)
                  )
                  <.ul(^.className := "times-summary", times.zipWithIndex.map {
                    case (((label, description), maybeSDate), idx) =>
                      val className = if (idx == times.length - 1) "last" else ""
                      <.li(^.className := className, <.div(^.className := "vert-align", <.div(<.div(<.h4(label, ^.title := description)), <.div(s"${
                        maybeSDate.map(lu => s"${timeAgo(lu)}").getOrElse("n/a")
                      }"))))
                  }.toVdomArray)
                },
                <.div(^.className := "clear"),
                <.h4("Recent connections"),
                <.ul(
                  feed.feedStatuses.statuses.sortBy(_.date).reverse.map {
                    case FeedStatusSuccess(date, updates) => <.li(s"${displayTime(date)}: $updates updates")
                    case FeedStatusFailure(date, _) => <.li(s"${displayTime(date)}: Connection failed")
                  }.toVdomArray
                )
              )
            }).toVdomArray
          })
        )
      }<commit_msg>DRTII-14 using port live feed name in comparison<commit_after>package drt.client.components

import drt.client.logger.{Logger, LoggerFactory}
import drt.client.modules.GoogleEventTracker
import drt.client.services.JSDateConversions.SDate
import drt.client.services.SPACircuit
import drt.shared.CrunchApi.MillisSinceEpoch
import drt.shared.{FeedSourceStatuses, FeedStatusFailure, FeedStatusSuccess, LiveFeedSource}
import japgolly.scalajs.react.vdom.html_<^._
import japgolly.scalajs.react.{Callback, ScalaComponent}

object StatusPage {

  val log: Logger = LoggerFactory.getLogger(getClass.getName)

  case class Props()

  val component = ScalaComponent.builder[Props]("StatusPage")
    .render_P { _ =>

      val feedStatusesRCP = SPACircuit.connect(_.feedStatuses)

      feedStatusesRCP { feedStatusesMP =>
        val feedStatusesPot = feedStatusesMP()

        <.div(
          <.h2("Feeds status"),
          feedStatusesPot.render((allFeedStatuses: Seq[FeedSourceStatuses]) => {
            val isLiveFeedAvailable = allFeedStatuses.count(_.feedSource.name == LiveFeedSource.name) > 0
            allFeedStatuses.map(feed => {
              <.div(^.className := s"feed-status ${feed.feedStatuses.ragStatus(SDate.now().millisSinceEpoch)}",
                <.h3(feed.feedSource.name),
                <.div(^.className := s"feed-status-description", <.p(feed.feedSource.description(isLiveFeedAvailable))),
                {
                  val times = Seq(
                    (("Updated", "When we last received new data"), feed.feedStatuses.lastUpdatesAt),
                    (("Checked", "When we last checked for new data"), feed.feedStatuses.lastSuccessAt),
                    (("Failed", "When we last experienced a failure with the feed"), feed.feedStatuses.lastFailureAt)
                  )
                  <.ul(^.className := "times-summary", times.zipWithIndex.map {
                    case (((label, description), maybeSDate), idx) =>
                      val className = if (idx == times.length - 1) "last" else ""
                      <.li(^.className := className, <.div(^.className := "vert-align", <.div(<.div(<.h4(label, ^.title := description)), <.div(s"${
                        maybeSDate.map(lu => s"${timeAgo(lu)}").getOrElse("n/a")
                      }"))))
                  }.toVdomArray)
                },
                <.div(^.className := "clear"),
                <.h4("Recent connections"),
                <.ul(
                  feed.feedStatuses.statuses.sortBy(_.date).reverse.map {
                    case FeedStatusSuccess(date, updates) => <.li(s"${displayTime(date)}: $updates updates")
                    case FeedStatusFailure(date, _) => <.li(s"${displayTime(date)}: Connection failed")
                  }.toVdomArray
                )
              )
            }).toVdomArray
          })
        )
      }
{'fraction_non_alphanumeric': 0.13603651044409337, 'fraction_numerical': 0.0024574337370545903, 'mean_word_length': 2.2119503945885004, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1085836', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1606, 'n_words': 285}