[Request for testing] Archive viewer for your postings

Preferences → Activity → [Download All] lets you download your activity data. The zip contains a file user_archive.csv. If you put this file in one directory with the attached database document, you get a searchable topic browser. Just open the form contained in the database.

Type of database: Embedded HSQL. Requires Java.

Embedded macro code: Only for the URL button loading the selected topic into your browser.

How to update your archive: Close the entire office, replace user_archive.csv and start again.

Usage: Should be obvious.

  • The criteria form in the top-left corner offers searching by date and day time, by language, substring searching with optional wildcards (% and _ instead of * and ?). The yellow text box searches case-insensitively the entered substring. Search string (upload:%.ods) finds postings with *.ods attachments.
  • All the other UI elements are on the navigation toolbar when the topic list is focussed.
  • Default sort order is descending by time which can be overridden.
  • When you apply your own form based filter or auto-filter, be aware that this filter is applied after the criteria based filter. It is a 2-stage filter.
  • When you right-click the column header of the list, you get additional columns such as the count of replies and the count of likes. By default (when loading the form) date, time and subject are shown.
    Ask.LO.odb (18.2 KB)

Apart from the filter criteria, no data are stored in the database document. All the data come from user_archive.csv…

image
image

Value too long also !!

1 Like

With a growing amount of user data, embedded HSQL fails at some point. The error message is misleading. The problem has nothing to do with any strings being too long. Postings with up to 10.000 characters are supported. Unforturnately, we can not use CLOB fields with linked text tables.

Here is a version of the same, upgraded to HSQL 2.4.1. Move your user_archive.csv into the database directory. The odb document has an auto-installer macro triggered on document open.

1 Like

@Villeroy , that’s an interesting approach!

I’m using an alternative “traditional” approach to displaying the same data in an ODS document.
You need to run the import_user_archive macro (Python) and select the user_archive... zip file downloaded from the forum in the file selection dialog.
The number in the URL column indicates the post’s sequence number in the thread.

# coding: utf-8
import zipfile
import csv
from io import TextIOWrapper
from datetime import datetime, timedelta

import uno
from com.sun.star.lang import Locale


def import_user_atchive(pyPath=None):

    if pyPath == None:
        ctx = XSCRIPTCONTEXT.getComponentContext()
        smgr = ctx.getServiceManager()
        file_picker = smgr.createInstanceWithContext(
            "com.sun.star.ui.dialogs.FilePicker", ctx
        )
        file_picker.appendFilter("user atchive", "user_archive*.zip")
        result = file_picker.execute()
        if result != 1:
            return None
        pyPath = file_picker.getSelectedFiles()[0]

    cols_title = [
        "Date",
        "URL",
        "Topic",
        "Post",
        "Categories",
        "PM",
        "Likes",
        "Replies",
    ]
    cols_width = [3, 1.5, 5, 15, 2, 1.5, 2, 2]   # centimeter

    formula_array = parse_user_archive(uno.fileUrlToSystemPath(pyPath), cols_title)

    doc = XSCRIPTCONTEXT.getDesktop().loadComponentFromURL(
        "private:factory/scalc", "_default", 0, ()
    )
    sheet = doc.Sheets.getByIndex(0)
    range = sheet.getCellRangeByPosition(
        0, 0, len(cols_title) - 1, len(formula_array) - 1
    )

    for i, value in enumerate(cols_width):
        col = range.getColumns().getByIndex(i)
        col.Width = int(value * 1000)

        if i == 0:  # Date
            col.NumberFormat = doc.getNumberFormats().addNewConverted(
                "YYYY-MM-DD HH:MM", Locale(Country="US", Language="en"), Locale()
            )

        elif i == 1:  # Url
            col.CellStyle = "Hyperlink"

        elif i == 2 or i == 3:  # Topic, Post
            col.IsTextWrapped = True

    range.CharLocale = Locale(Language="zxx")

    range.setFormulaArray(formula_array)

    range.getRows().getByIndex(0).CellStyle = "Accent 3"  # header row

    disp = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
    frame = doc.CurrentController.Frame
    for uno_cmd in ("DataFilterAutoFilter", "FreezePanesRow"): 
        disp.executeDispatch(frame, f".uno:{uno_cmd}", "", 0, ())

    sheet.setName("user_archive")
    doc.setTitle(pyPath.rsplit("/", 1)[1].rsplit(".", 1)[0])  


def parse_user_archive(path, cols_title):
    with zipfile.ZipFile(path, "r") as zip_file:
        with zip_file.open("user_archive.csv") as csv_file:
            text_file = TextIOWrapper(csv_file, encoding="utf-8")
            csv_reader = csv.reader(text_file, delimiter=",", quotechar='"')

            out = [cols_title]
             
            # csv file header row:
            # topic_title,categories,is_pm,post,like_count,reply_count,url,created_at
            #     [0]         [1]     [2]   [3]    [4]        [5]      [6]    [7]
            for row in csv_reader:
                if csv_reader.line_num > 1:
                    url = row[6]
                    num_post = url.rsplit("/", 1)[1]
                    dt = date_to_excel_date(datetime.fromisoformat(row[7][:-1]))
                    out.append(
                        [
                            dt,
                            f'=HYPERLINK("{url}";"{num_post}")',
                            row[0],
                            row[3],
                            row[1],
                            1 if row[2] == "Yes" else "",
                            row[4],
                            row[5],
                        ]
                    )

            return out


def date_to_excel_date(pydate, nulldate=datetime(1899, 12, 30)):
    return (pydate - nulldate) / timedelta(days=1)


g_exportedScripts = (import_user_atchive,)

UserArchive.ods (10.9 KB)

If I wanted to have datbase data in spreadsheets, I would import the csv and remove “Z” from the time stamp column.