Beispiel #1
0
def run_gerne_discovery(month_ucis):
    genres = [
        'Barn/ungdom', 'Dramaserie', 'Komediserie', 'Krim/thrillerserie',
        'Fotboll'
    ]
    res = []
    for genre in genres:
        genre_ucis = month_ucis.filter(month_ucis.category == genre)
        genre_top_programs = top_programs_by_view_count(genre_ucis)
        table = Table()
        table.title = "top programs for {} last month".format(genre)

        def row_dict(x):
            return {
                "content": {
                    "names": [{
                        "value": x['title']
                    }]
                },
                "source": {
                    "ID": x['channelID'],
                    "name": x['channelName']
                },
                "values": [{
                    "name": "view count",
                    "data": x['viewCount']
                }]
            }

        table_rows = [TableRow(**row_dict(x)) for x in genre_top_programs]
        table.rows = table_rows
        res.append(table.as_ui_dict())
    return res
Beispiel #2
0
def unpopular_completed_contents():
    res = r.db('gettv_insight_api').table('content_overview')\
        .filter(
            (r.row['content-completion'] > 0.8)
        )\
        .filter(
            (r.row['content-total-started-views'] < 5000)
        )\
        .order_by('content-completion')\
        .run()
    table = Table()
    table.title = "unpopular high completion contents"
    def row_dict(x):
        return {
            "content": {
                "inventoryID": all_titles[x['title']],
                "names": [{'value': x['title']}]
            },
            "values": [{
                "name": "view count",
                "data": x['content-total-started-views']
            },
            {
                "name": "content completion",
                "unit": "percentage",
                "data": x['content-completion']
            }]
        }
    table_rows = [TableRow(**row_dict(x)) for x in res][:10]
    table.rows = table_rows
    return table.as_ui_dict(exclude_version=True)
Beispiel #3
0
def unpopular_completed_channels():
    channel_dict = channleID_to_channelName()
    res = r.db('telenortv_insight_api').table('channel_overview')\
        .filter(
            (r.row['content-completion'] > 0.55)
        )\
        .order_by('content-completion')\
        .run()
    table = Table()
    table.title = "unpopular high completion channels"

    def row_dict(x):
        return {
            "source": {
                "ID": x['channelID'],
                "name": channel_dict[x['channelID']]
            },
            "values": [{
                "name": "view count",
                "data": x['channel-total-started-views']
            }, {
                "name": "content completion",
                "unit": "percentage",
                "data": x['content-completion']
            }]
        }

    table_rows = [TableRow(**row_dict(x)) for x in res]
    table.rows = table_rows
    return table.as_ui_dict(exclude_version=True)
Beispiel #4
0
def genre_completion(week_ucis):
    genre_by_completion_ratio = top_tag_by_completion_ratio(week_ucis, 'category')
    table = Table()
    table.title = "top genres by content completion"
    def row_dict(x):
        return {
            "genre": {"names": [{"value": x[0]}]},
            "values": [{
                "name": "content completion",
                "unit": "percentage",
                "data": x[1]
            }]
        }
    table_rows = [TableRow(**row_dict(x)) for x in genre_by_completion_ratio]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #5
0
def most_popular_contents():
    res = r.db('gettv_insight_api').table('content_overview')\
        .order_by('content-total-started-views')\
        .run()
    table = Table()
    table.title = "all time most popular contents"
    def row_dict(x):
        return {
            "content": {
                "inventoryID": all_titles[x['title']],
                "names": [{'value': x['title']}]
            },
            "values": [{
                "name": "view count",
                "data": x['content-total-started-views']
            }]
        }
    table_rows = [TableRow(**row_dict(x)) for x in reversed(res)][:10]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #6
0
def all_time_top_programs():
    channel_dict = channleID_to_channelName()
    spark_io = SparkParquetIO()
    ucis = spark_io.get_all_interactions()
    top_programs = top_programs_by_viewtime(ucis, row_limit=20)
    table = Table()
    table.title = "all time top programs by viewing time"
    table.subtitle = "programs most watched"

    def row_dict(x):
        return {
            "content": {
                "names": [{
                    "value": x[0]
                }]
            },
            "source": {
                "ID": x[1],
                "name": channel_dict[x[1]]
            },
            "values": [{
                "name": "minutes",
                "data": x[2]
            }]
        }

    table_rows = [TableRow(**row_dict(x)) for x in top_programs]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #7
0
def midnight_favorites(week_ucis):
    midnight_top_programs = midnight_favorite_programs(week_ucis)
    table = Table()
    table.title = "top programs in midnight"
    table.subtitle = "programs most watched between 22:00 to 01:00"

    def row_dict(x):
        return {
            "content": {
                "names": [{
                    "value": x[0]
                }]
            },
            "source": {
                "ID": x[2],
                "name": x[1]
            },
            "values": [{
                "name": "view count",
                "data": x[3]
            }]
        }

    table_rows = [TableRow(**row_dict(x)) for x in midnight_top_programs]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #8
0
def run_gerne_discovery(month_ucis):
    genres = ['drama', 'komedie', 'barn']
    res = []
    for genre in genres:
        genre_ucis = month_ucis.filter(month_ucis.category==genre)
        genre_top_programs = top_programs_by_view_count(genre_ucis)
        table = Table()
        table.title = "top programs for {} last month".format(genre)
        def row_dict(x):
            return {
                "content": {
                    "names": [{"value": x['title']}]
                },
                "values": [{
                    "name": "view count",
                    "data": x['viewCount']
                }]
            }
        table_rows = [TableRow(**row_dict(x)) for x in genre_top_programs]
        table.rows = table_rows
        res.append(table.as_ui_dict())
    return res
Beispiel #9
0
def channel_completion(week_ucis):
    channel_dict = channleID_to_channelName()
    channel_by_completion_ratio = top_tag_by_completion_ratio(
        week_ucis, 'channelID')
    table = Table()
    table.title = "top channels by content completion"

    def row_dict(x):
        return {
            "source": {
                "ID": x[0],
                "name": channel_dict[x[0]]
            },
            "values": [{
                "name": "content completion",
                "unit": "percentage",
                "data": x[1]
            }]
        }

    table_rows = [TableRow(**row_dict(x)) for x in channel_by_completion_ratio]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #10
0
def genre_user_viewtime(week_ucis):
    genre_by_user_viewtime = top_tag_by_user_viewtime(week_ucis, 'category')
    table = Table()
    table.title = "top genres by user viewing time"
    table.subtitle = "top genres by user viewing time"
    def row_dict(x):
        return {
            "genre": {"names": [{"value": x[0]}]},
            "values": [{
                "name": "viewing time",
                "unit": "minutes",
                "data": x[1]
            }]
        }
    table_rows = [TableRow(**row_dict(x)) for x in genre_by_user_viewtime]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #11
0
def content_user_viewtime(week_ucis):
    content_by_user_viewtime = top_tag_by_user_viewtime(week_ucis, 'title')
    table = Table()
    table.title = "top contents by user viewing time"
    table.subtitle = "top contents by user viewing time"
    def row_dict(x):
        return {
            "content": {
                "names": [{"value": x[0]}]
            },
            "values": [{
                "name": "viewing time",
                "unit": "minutes",
                "data": x[1]
            }]
        }
    table_rows = [TableRow(**row_dict(x)) for x in content_by_user_viewtime]
    table.rows = table_rows
    return table.as_ui_dict()
Beispiel #12
0
def channel_user_viewtime(week_ucis):
    channel_dict = channleID_to_channelName()
    channel_by_user_viewtime = top_tag_by_user_viewtime(week_ucis, 'channelID')
    table = Table()
    table.title = "top channels by user viewing time"
    table.subtitle = "top channels by user viewing time"

    def row_dict(x):
        return {
            "source": {
                "ID": x[0],
                "name": channel_dict[x[0]]
            },
            "values": [{
                "name": "viewing time",
                "unit": "minutes",
                "data": x[1]
            }]
        }

    table_rows = [TableRow(**row_dict(x)) for x in channel_by_user_viewtime]
    table.rows = table_rows
    return table.as_ui_dict()