You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/10/23 16:58:55 UTC
[kibble] 03/04: Add WIP mood analysis page for email
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git
commit b9dc52d419fda08a8feac2875ff299f34f9d8ff6
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Oct 23 18:58:26 2017 +0200
Add WIP mood analysis page for email
---
api/pages/mail/mood.py | 134 +++++++++++++++++++++++++++++++++++++++++++++++++
api/yaml/widgets.yaml | 32 ++++++++++++
2 files changed, 166 insertions(+)
diff --git a/api/pages/mail/mood.py b/api/pages/mail/mood.py
new file mode 100644
index 0000000..4950173
--- /dev/null
+++ b/api/pages/mail/mood.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+########################################################################
+# OPENAPI-URI: /api/mail/mood
+########################################################################
+# get:
+# responses:
+# '200':
+# content:
+# application/json:
+# schema:
+# $ref: '#/components/schemas/Sloc'
+# description: 200 Response
+# default:
+# content:
+# application/json:
+# schema:
+# $ref: '#/components/schemas/Error'
+# description: unexpected error
+# security:
+# - cookieAuth: []
+# summary: Shows a breakdown of the (analyzed) mood in emails
+# post:
+# requestBody:
+# content:
+# application/json:
+# schema:
+# $ref: '#/components/schemas/defaultWidgetArgs'
+# responses:
+# '200':
+# content:
+# application/json:
+# schema:
+# $ref: '#/components/schemas/Sloc'
+# description: 200 Response
+# default:
+# content:
+# application/json:
+# schema:
+# $ref: '#/components/schemas/Error'
+# description: unexpected error
+# security:
+# - cookieAuth: []
+# summary: Shows a breakdown of the (analyzed) mood in emails
+#
+########################################################################
+
+
+
+
+
+"""
+This is the email mood renderer for Kibble
+"""
+
+import json
+
+def run(API, environ, indata, session):
+
+ # We need to be logged in for this!
+ if not session.user:
+ raise API.exception(403, "You must be logged in to use this API endpoint! %s")
+
+
+ # First, fetch the view if we have such a thing enabled
+ viewList = []
+ if indata.get('view'):
+ viewList = session.getView(indata.get('view'))
+ if indata.get('subfilter'):
+ viewList = session.subFilter(indata.get('subfilter'), view = viewList)
+
+
+ # Fetch all sources for default org
+ dOrg = session.user['defaultOrganisation'] or "apache"
+ query = {
+ 'query': {
+ 'bool': {
+ 'must': [
+ {
+ 'term': {
+ 'organisation': dOrg
+ }
+ }
+ ]
+ }
+ },
+ 'sort': [{'ts': 'desc'}]
+ }
+ # Source-specific or view-specific??
+ if indata.get('source'):
+ query['query']['bool']['must'].append({'term': {'sourceID': indata.get('source')}})
+ elif viewList:
+ query['query']['bool']['must'].append({'terms': {'sourceID': viewList}})
+
+ res = session.DB.ES.search(
+ index=session.DB.dbname,
+ doc_type="email",
+ size = 5000,
+ body = query
+ )
+
+ moods = {}
+ years = 0
+ for hit in res['hits']['hits']:
+ doc = hit['_source']
+ if 'mood' in doc:
+ mood = doc['mood']
+ for k, v in mood.items():
+ moods[k] = moods.get(k, [0,0])
+ moods[k][0] += 1
+ moods[k][1] += v
+
+ mood_compiled = {}
+ for k, v in moods.items():
+ mood_compiled[k] = int( (v[1] / v[0]) * 100)
+ JSON_OUT = {
+ 'counts': mood_compiled,
+ 'okay': True
+ }
+ yield json.dumps(JSON_OUT)
diff --git a/api/yaml/widgets.yaml b/api/yaml/widgets.yaml
index 13856ca..0b3fa87 100644
--- a/api/yaml/widgets.yaml
+++ b/api/yaml/widgets.yaml
@@ -635,3 +635,35 @@ widgets:
source: "org/members"
name: "Organisation members"
blocks: 12
+
+## EMAIL MOOD
+ mail-mood:
+ title: "Mailing list moods"
+ rows:
+ -
+ name: "Date picker row"
+ children:
+ -
+ type: "datepicker"
+ blocks: 4
+ name: "Date picker"
+ -
+ type: "viewpicker"
+ blocks: 4
+ source: "views"
+ name: "Quick filter"
+ -
+ type: mailpicker
+ blocks: 4
+ source: "sources"
+ eargs:
+ types: ['mail', 'ponymail', 'pipermail', 'hyperkitty']
+ name: Mailing list picker"
+ -
+ name: "Trends"
+ children:
+ -
+ type: "line"
+ source: "mail/mood"
+ name: "Mailing list mood"
+ blocks: 12
--
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.