Return more tag details with item insights

This commit is contained in:
Eike Kettner 2020-08-08 00:41:20 +02:00
parent c8ad9bf11f
commit a4796f3f7f
5 changed files with 36 additions and 13 deletions

View File

@ -43,6 +43,9 @@ trait OCollective[F[_]] {
object OCollective {
type TagCount = QCollective.TagCount
val TagCount = QCollective.TagCount
type InsightData = QCollective.InsightData
val insightData = QCollective.InsightData

View File

@ -3050,19 +3050,33 @@ components:
items:
type: array
items:
$ref: "#/components/schemas/NameCount"
NameCount:
$ref: "#/components/schemas/TagCount"
TagCount:
description: |
Generic structure for counting something.
required:
- name
- tag
- count
properties:
name:
type: string
tag:
$ref: "#/components/schemas/TagLight"
count:
type: integer
format: int32
TagLight:
description: |
A subset of tag properties.
required:
- id
- name
properties:
id:
type: string
format: ident
name:
type: string
category:
type: string
AttachmentMeta:
description: |
Extracted meta data of an attachment.

View File

@ -31,9 +31,12 @@ trait Conversions {
d.incoming,
d.outgoing,
d.bytes,
TagCloud(d.tags.toList.map(p => NameCount(p._1, p._2)))
TagCloud(d.tags.map(tc => TagCount(mkTagLight(tc), tc.count)))
)
def mkTagLight(t: OCollective.TagCount): TagLight =
TagLight(t.id, t.name, t.category)
// attachment meta
def mkAttachmentMeta(rm: RAttachmentMeta): AttachmentMeta =
AttachmentMeta(

View File

@ -11,12 +11,13 @@ import doobie._
import doobie.implicits._
object QCollective {
case class TagCount(id: Ident, name: String, category: Option[String], count: Int)
case class InsightData(
incoming: Int,
outgoing: Int,
bytes: Long,
tags: Map[String, Int]
tags: List[TagCount]
)
def getInsights(coll: Ident): ConnectionIO[InsightData] = {
@ -52,7 +53,9 @@ object QCollective {
) as t""".query[Option[Long]].unique
val q3 = fr"SELECT" ++ commas(
TC.tid.prefix("t").f,
TC.name.prefix("t").f,
TC.category.prefix("t").f,
fr"count(" ++ RC.itemId.prefix("r").f ++ fr")"
) ++
fr"FROM" ++ RTagItem.table ++ fr"r" ++
@ -60,14 +63,14 @@ object QCollective {
.prefix("r")
.is(TC.tid.prefix("t")) ++
fr"WHERE" ++ TC.cid.prefix("t").is(coll) ++
fr"GROUP BY" ++ TC.name.prefix("t").f
fr"GROUP BY" ++ commas(TC.name.prefix("t").f, TC.tid.prefix("t").f, TC.category.prefix("t").f)
for {
n0 <- q0
n1 <- q1
n2 <- fileSize
n3 <- q3.query[(String, Int)].to[Vector]
} yield InsightData(n0, n1, n2.getOrElse(0L), Map.from(n3))
n3 <- q3.query[TagCount].to[List]
} yield InsightData(n0, n1, n2.getOrElse(0L), n3)
}
def getContacts(

View File

@ -1,6 +1,6 @@
module Page.CollectiveSettings.View exposing (view)
import Api.Model.NameCount exposing (NameCount)
import Api.Model.TagCount exposing (TagCount)
import Comp.CollectiveSettingsForm
import Comp.SourceManage
import Comp.UserManage
@ -145,14 +145,14 @@ viewInsights model =
]
makeTagStats : NameCount -> Html Msg
makeTagStats : TagCount -> Html Msg
makeTagStats nc =
div [ class "ui statistic" ]
[ div [ class "value" ]
[ String.fromInt nc.count |> text
]
, div [ class "label" ]
[ text nc.name
[ text nc.tag.name
]
]