问:
Problem with Docker- buid.sh: received: WARNING: The COMPOSE_PROJECT_NAME variable is not set. Defaulting to a blank string
I ve got a problem when running $ ./docker-build.sh I receive the following Warnings.

```<code>WARNING: The COMPOSE_PROJECT_NAME variable is not set. Defaulting to a blank string.
WARNING: The HTTPS_HOST variable is not set. Defaulting to a blank string.
WARNING: The HTTP_HOST variable is not set. Defaulting to a blank string.
WARNING: The HTTPS_PORT variable is not set. Defaulting to a blank string.
WARNING: The HTTP_PORT variable is not set. Defaulting to a blank string.
WARNING: The LETSENCRYPT_MODE variable is not set. Defaulting to a blank string.
WARNING: The ADMIN_EMAIL variable is not set. Defaulting to a blank string.
WARNING: The POSTGRESQL_MAX_CONNECTIONS variable is not set. Defaulting to a blank string.
WARNING: The JENKINS_HTTP_PORT variable is not set. Defaulting to a blank string.
WARNING: The JENKINS_HTTPS_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports value [':', ':', '50000:50000'] has non-unique elements

</code>```

My docker compose version is v2.5.0 on Ubuntu 22.04.

I tried running $ docker compose up -d. My docker compose version is v2.5.0 on Ubuntu 22.04. If I run the command: $ docker compose up -d I get the following Warnings:

```<code>WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "ADMIN_EMAIL" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRESQL_MAX_CONNECTIONS" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
services.jenkins.ports array items[0,1] must be unique
</code>```

My Dockerfile is

```<code>FROM python:3.10.2-buster
LABEL GeoNode development team

RUN mkdir -p /usr/src/communalp

# Enable postgresql-client-13
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN echo "deb http://deb.debian.org/debian/ stable main contrib non-free" | tee /etc/apt/sources.list.d/debian.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# To get GDAL 3.2.1 to fix this issue https://github.com/OSGeo/gdal/issues/1692
# TODO: The following line should be removed if base image upgraded to Bullseye
RUN echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" | tee /etc/apt/sources.list.d/debian.list

# This section is borrowed from the official Django image but adds GDAL and others
RUN apt-get update -y && apt-get upgrade -y

# Prepraing dependencies
RUN apt-get install -y \
    libgdal-dev libpq-dev libxml2-dev \
    libxml2 libxslt1-dev zlib1g-dev libjpeg-dev \
    libmemcached-dev libldap2-dev libsasl2-dev libffi-dev

RUN apt-get install -y --no-install-recommends \
    gcc zip gettext geoip-bin cron \
    postgresql-client-13 \
    sqlite3 spatialite-bin libsqlite3-mod-spatialite \
    python3-dev python3-gdal python3-psycopg2 python3-ldap \
    python3-pip python3-pil python3-lxml python3-pylibmc \
    uwsgi uwsgi-plugin-python3 \
    firefox-esr

RUN apt-get install -y devscripts build-essential debhelper pkg-kde-tools sharutils
# RUN git clone https://salsa.debian.org/debian-gis-team/proj.git /tmp/proj
# RUN cd /tmp/proj && debuild -i -us -uc -b && dpkg -i ../*.deb

# Install pip packages
RUN pip install pip --upgrade \
    && pip install pygdal==$(gdal-config --version).* \
        flower==0.9.4

# Activate "memcached"
RUN apt install -y memcached
RUN pip install pylibmc \
    && pip install sherlock

# add bower and grunt command
COPY src /usr/src/communalp/
WORKDIR /usr/src/communalp

COPY src/monitoring-cron /etc/cron.d/monitoring-cron
RUN chmod 0644 /etc/cron.d/monitoring-cron
RUN crontab /etc/cron.d/monitoring-cron
RUN touch /var/log/cron.log
RUN service cron start

COPY src/wait-for-databases.sh /usr/bin/wait-for-databases
RUN chmod +x /usr/bin/wait-for-databases
RUN chmod +x /usr/src/communalp/tasks.py \
    && chmod +x /usr/src/communalp/entrypoint.sh

COPY src/celery.sh /usr/bin/celery-commands
RUN chmod +x /usr/bin/celery-commands

COPY src/celery-cmd /usr/bin/celery-cmd
RUN chmod +x /usr/bin/celery-cmd

# # Install "geonode-contribs" apps
# RUN cd /usr/src; git clone https://github.com/GeoNode/geonode-contribs.git -b master
# # Install logstash and centralized dashboard dependencies
# RUN cd /usr/src/geonode-contribs/geonode-logstash; pip install --upgrade  -e . \
#     cd /usr/src/geonode-contribs/ldap; pip install --upgrade  -e .

RUN pip install --upgrade --no-cache-dir  --src /usr/src -r requirements.txt
RUN pip install --upgrade  -e .

# Cleanup apt update lists
RUN rm -rf /var/lib/apt/lists/*

# Export ports
EXPOSE 8000

# We provide no command or entrypoint as this image can be used to  enter code here`serve the django project or run celery tasks
# ENTRYPOINT /usr/src/communalp/entrypoint.sh
</code>```

I'd be glad for any help. Thanks

Cheers Phil

Body:
I ve got a problem when running $ ./docker-build.sh I receive the following Warnings.

WARNING: The COMPOSE_PROJECT_NAME variable is not set. Defaulting to a blank string.
WARNING: The HTTPS_HOST variable is not set. Defaulting to a blank string.
WARNING: The HTTP_HOST variable is not set. Defaulting to a blank string.
WARNING: The HTTPS_PORT variable is not set. Defaulting to a blank string.
WARNING: The HTTP_PORT variable is not set. Defaulting to a blank string.
WARNING: The LETSENCRYPT_MODE variable is not set. Defaulting to a blank string.
WARNING: The ADMIN_EMAIL variable is not set. Defaulting to a blank string.
WARNING: The POSTGRESQL_MAX_CONNECTIONS variable is not set. Defaulting to a blank string.
WARNING: The JENKINS_HTTP_PORT variable is not set. Defaulting to a blank string.
WARNING: The JENKINS_HTTPS_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports value [':', ':', '50000:50000'] has non-unique elements

My docker compose version is v2.5.0 on Ubuntu 22.04.

I tried running $ docker compose up -d. My docker compose version is v2.5.0 on Ubuntu 22.04. If I run the command: $ docker compose up -d I get the following Warnings:

WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "ADMIN_EMAIL" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRESQL_MAX_CONNECTIONS" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
services.jenkins.ports array items[0,1] must be unique

My Dockerfile is

FROM python:3.10.2-buster
LABEL GeoNode development team

RUN mkdir -p /usr/src/communalp

# Enable postgresql-client-13
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN echo "deb http://deb.debian.org/debian/ stable main contrib non-free" | tee /etc/apt/sources.list.d/debian.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# To get GDAL 3.2.1 to fix this issue https://github.com/OSGeo/gdal/issues/1692
# TODO: The following line should be removed if base image upgraded to Bullseye
RUN echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" | tee /etc/apt/sources.list.d/debian.list

# This section is borrowed from the official Django image but adds GDAL and others
RUN apt-get update -y && apt-get upgrade -y

# Prepraing dependencies
RUN apt-get install -y \
    libgdal-dev libpq-dev libxml2-dev \
    libxml2 libxslt1-dev zlib1g-dev libjpeg-dev \
    libmemcached-dev libldap2-dev libsasl2-dev libffi-dev

RUN apt-get install -y --no-install-recommends \
    gcc zip gettext geoip-bin cron \
    postgresql-client-13 \
    sqlite3 spatialite-bin libsqlite3-mod-spatialite \
    python3-dev python3-gdal python3-psycopg2 python3-ldap \
    python3-pip python3-pil python3-lxml python3-pylibmc \
    uwsgi uwsgi-plugin-python3 \
    firefox-esr

RUN apt-get install -y devscripts build-essential debhelper pkg-kde-tools sharutils
# RUN git clone https://salsa.debian.org/debian-gis-team/proj.git /tmp/proj
# RUN cd /tmp/proj && debuild -i -us -uc -b && dpkg -i ../*.deb

# Install pip packages
RUN pip install pip --upgrade \
    && pip install pygdal==$(gdal-config --version).* \
        flower==0.9.4

# Activate "memcached"
RUN apt install -y memcached
RUN pip install pylibmc \
    && pip install sherlock

# add bower and grunt command
COPY src /usr/src/communalp/
WORKDIR /usr/src/communalp

COPY src/monitoring-cron /etc/cron.d/monitoring-cron
RUN chmod 0644 /etc/cron.d/monitoring-cron
RUN crontab /etc/cron.d/monitoring-cron
RUN touch /var/log/cron.log
RUN service cron start

COPY src/wait-for-databases.sh /usr/bin/wait-for-databases
RUN chmod +x /usr/bin/wait-for-databases
RUN chmod +x /usr/src/communalp/tasks.py \
    && chmod +x /usr/src/communalp/entrypoint.sh

COPY src/celery.sh /usr/bin/celery-commands
RUN chmod +x /usr/bin/celery-commands

COPY src/celery-cmd /usr/bin/celery-cmd
RUN chmod +x /usr/bin/celery-cmd

# # Install "geonode-contribs" apps
# RUN cd /usr/src; git clone https://github.com/GeoNode/geonode-contribs.git -b master
# # Install logstash and centralized dashboard dependencies
# RUN cd /usr/src/geonode-contribs/geonode-logstash; pip install --upgrade  -e . \
#     cd /usr/src/geonode-contribs/ldap; pip install --upgrade  -e .

RUN pip install --upgrade --no-cache-dir  --src /usr/src -r requirements.txt
RUN pip install --upgrade  -e .

# Cleanup apt update lists
RUN rm -rf /var/lib/apt/lists/*

# Export ports
EXPOSE 8000

# We provide no command or entrypoint as this image can be used to  enter code here`serve the django project or run celery tasks
# ENTRYPOINT /usr/src/communalp/entrypoint.sh

I'd be glad for any help. Thanks

Cheers Phil


来源: stackexchange

问:
Parsing XML to CSV or YAML - Error "CData section not finished"
I'm trying to parse data collected from a Checkpoint firewall which is in XML format. Ideally, I would like XML data converted to csv or xml format. Once I'm there then I'm good.

Top of XML Text

```<code><?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="../network_objects.xsl"?>
</code>```

Code I'm trying, this code I got from other posts.

```<code>from lxml import etree
file = "network_objects.xml"
parser = etree.XMLParser(encoding = "iso-8859-1")
tree = etree.parse(file, parser)
</code>```

Error I'm getting. I don't know anything about XML and what CData is. Can someone provide some guidance?

```<code>lxml.etree.XMLSyntaxError: CData section not finished
Petroleum Traders public tunnel IPë½¨Äë»¼, line 6787, column 651
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to parse data collected from a Checkpoint firewall which is in XML format. Ideally, I would like XML data converted to csv or xml format. Once I'm there then I'm good.

Top of XML Text

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="../network_objects.xsl"?>

Code I'm trying, this code I got from other posts.

from lxml import etree
file = "network_objects.xml"
parser = etree.XMLParser(encoding = "iso-8859-1")
tree = etree.parse(file, parser)

Error I'm getting. I don't know anything about XML and what CData is. Can someone provide some guidance?

lxml.etree.XMLSyntaxError: CData section not finished
Petroleum Traders public tunnel IPë½¨Äë»¼, line 6787, column 651


问:
SAP SLT - Restrict no of sessions to 5 for a particular subscription
I am working on POC to ingest data from SAP SLT. I will fire ingestion for a batch of tables(around 50) parallelly, but when I do so, it is increasing the load on the SLT end. I want to make sure only five ingestion sessions are active at one point of time. Is there any way to do this via SLT side?

PS - I cant do it at the target/ingestion end as there are some limitations with the ingestion tool.


问:
javascript node command line debugging

I'm trying to debug javascript code with node inspect on terminal

I can step through, and set breakpoints, but can not inspect values

For instance, I get an error when I try to print i below:

$ npx tsc --strict main.ts # <--- compiled from typescript
$ node inspect ./main.js   # <--- run with node inspect
< Debugger listening on < ... omitted ... >
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
<
 ok
Break on start in main.js:12
 10     return true;
 11 }
>12 console.log(isPrime(8));
 13
debug> sb(6)
  1 "use strict";
  2 function isPrime(p) {
  3     for (var i = 2; i < p; i++) {
  4         for (var j = 2; j
 6                 return false;
  7             }
  8         }
  9     }
 10     return true;
 11 }
```
<p>Here is the error message I get in the terminal:</p>
<pre class="lang-bash prettyprint-override"><code>debug> console.log(i)
REPL2:1
console.log(i)
            ^

Uncaught ReferenceError: i is not defined
    at REPL2:1:13
    at Script.runInContext (node:vm:141:12)
    ... omitted for brevity ...
</code>```

Title: javascript node command line debugging

Body:
I'm trying to debug javascript code with node inspect on terminal

I can step through, and set breakpoints, but can not inspect values

For instance, I get an error when I try to print i below:

$ npx tsc --strict main.ts # <--- compiled from typescript
$ node inspect ./main.js   # <--- run with node inspect
< Debugger listening on < ... omitted ... >
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
<
 ok
Break on start in main.js:12
 10     return true;
 11 }
>12 console.log(isPrime(8));
 13
debug> sb(6)
  1 "use strict";
  2 function isPrime(p) {
  3     for (var i = 2; i < p; i++) {
  4         for (var j = 2; j
 6                 return false;
  7             }
  8         }
  9     }
 10     return true;
 11 }

Here is the error message I get in the terminal:

debug> console.log(i)
REPL2:1
console.log(i)
            ^

Uncaught ReferenceError: i is not defined
    at REPL2:1:13
    at Script.runInContext (node:vm:141:12)
    ... omitted for brevity ...


问:
Is Angular's "cdkDrag" preventing *ngIf from removing html element?
I have a draggable div which has a button inside of it that toggles a boolean called 'open' draggable card with button.
That boolean, 'open', is used to display a mat-card inside of that div (using ngIf) which is positioned to the right of it with position: absolute.
div with opened child element.

I now want to remove that child element by setting 'open' to false when the user begins to drag the div around. I tried this by calling a method that sets 'open' to false when (cdkDragStarted) is called: ' (cdkDragStarted)="close()" '. This works, and the boolean is set to false, but the ngIf does not remove the element until after the user drops the div. Did I miss something, or does the dragging of the div somehow interfere with the ngIf?

Tried using the cdkDragStarted event to set 'open' to false and therefore remove a child element of that draggable div (by checking the state of the boolean with ngIf)

That element only gets removed after the draggable div is dropped by the user, although the boolean is already set to false when the div gets picked up.

The structure of the part where I am having issues looks a bit like this (there are other elements in the cdkDropList, but I didn't want to overcomplicate things):

```<code><div cdkDropList cdkDropListOrientation="horizontal">

    <div cdkDrag cdkDragLockAxis="x" (cdkDragStarted)="close()">

     <button *ngIf="!open" (click)="open()"> </button>

     <mat-card *ngIf="open">

     </mat-card>

    </div>

</div>
</code>```

Update: For testing purposes I also tried conditionally showing an h1 outside of the cdkDrag div. This h1 shows up as soon as I pickup the div. So I guess removing children of a cdkDrag element, while it is picked up by the user, is just not possible.

Body:
I have a draggable div which has a button inside of it that toggles a boolean called 'open' draggable card with button.
That boolean, 'open', is used to display a mat-card inside of that div (using ngIf) which is positioned to the right of it with position: absolute.
div with opened child element.

I now want to remove that child element by setting 'open' to false when the user begins to drag the div around. I tried this by calling a method that sets 'open' to false when (cdkDragStarted) is called: ' (cdkDragStarted)="close()" '. This works, and the boolean is set to false, but the ngIf does not remove the element until after the user drops the div. Did I miss something, or does the dragging of the div somehow interfere with the ngIf?

Tried using the cdkDragStarted event to set 'open' to false and therefore remove a child element of that draggable div (by checking the state of the boolean with ngIf)

That element only gets removed after the draggable div is dropped by the user, although the boolean is already set to false when the div gets picked up.

The structure of the part where I am having issues looks a bit like this (there are other elements in the cdkDropList, but I didn't want to overcomplicate things):

     <button *ngIf="!open" (click)="open()"> </button>

     <mat-card *ngIf="open">

     </mat-card>

Update: For testing purposes I also tried conditionally showing an h1 outside of the cdkDrag div. This h1 shows up as soon as I pickup the div. So I guess removing children of a cdkDrag element, while it is picked up by the user, is just not possible.


问:
How can I use an attribute imported from a Roslyn analyzer project?
I'm working on a Roslyn analyzer, which is designed to only analyze methods that the user marks with an attribute. My challenge comes with this "designation" idea; if I create the attribute in the analyzer project and test the nuget package that I produce, the source cannot even import the namespace of the analyzer. If I had to guess, this is because the package is designated as an "Analyzer" and namespaces and types cannot be included from it. I suppose that I could get around this issue by creating a second package just for this attribute, but that seems like it would be inconvenient to users.

Currently, in my analyzer I have the following source file:

namespace MyAnalyzer;

[AttributeUsage(AttributeTargets.Method)]
public class AnalyzeMeAttribute : Attribute
{
}
```
<p>And in my test console project, I have installed the analyzer's nuget package and written the following:</p>
<pre class="lang-cs prettyprint-override"><code>using MyAnalyzer;

public class ProgramMainClass
{
    [AnalyzeMe]
    public static void Main()
    {
    }
}
</code>```

When I try to compile, I get a handful of CS0246 ("The type or namespace <name> could not be found") errors.

Body:
I'm working on a Roslyn analyzer, which is designed to only analyze methods that the user marks with an attribute. My challenge comes with this "designation" idea; if I create the attribute in the analyzer project and test the nuget package that I produce, the source cannot even import the namespace of the analyzer. If I had to guess, this is because the package is designated as an "Analyzer" and namespaces and types cannot be included from it. I suppose that I could get around this issue by creating a second package just for this attribute, but that seems like it would be inconvenient to users.

Currently, in my analyzer I have the following source file:

namespace MyAnalyzer;

[AttributeUsage(AttributeTargets.Method)]
public class AnalyzeMeAttribute : Attribute
{
}

And in my test console project, I have installed the analyzer's nuget package and written the following:

using MyAnalyzer;

public class ProgramMainClass
{
    [AnalyzeMe]
    public static void Main()
    {
    }
}

When I try to compile, I get a handful of CS0246 ("The type or namespace <name> could not be found") errors.


问:
Understanding ANOVA test result
I am running ANOVA test to compare the performance of regression models in Python. However, I don't seem to understand my results and can't interpret them.
Here is a result with NaN value in the first row.

And here is another table with NaN values in both rows.

I would appreciate any help understanding these outcomes or recommendations about other methods I could use.

Title: Understanding ANOVA test result


问:
getStaticProps with getStaticPaths but changes don't affect
So, In Next.js, I'm trying to build a website, that has products, and I want to build each page for SEO and inject Meta tags so the Google can index them correctly, but for example the content inside can change also other stuff, and I don't know to handle this, what I can do in this case?


问:
Dynamically import a module Next.js, but with server side rendering
I have a [...pageId].tsx file in the /pages directory.

In getServerSideProps, the page will check a CMS, and find a list of components to render. I want to load those components serverside, then render them out, then return the page.

Using next/dynamic like below will load the components, but it will not render them serverside. They will only stream in on the client. In other words: the customer will see 'Loading...' first, then the component renders. That's not what I want, also not for SEO.

```<code>const getDynamicComponent = (c) => dynamic(() => import(`../../components/${c}`), {
  loading: () => <section>Loading...</section>,
  ssr: true
});

export default function SomePage({page}) {
  // Load dynamic component if necessary
  let DynamicComponent = getDynamicComponent(page.reactComponent);
  }
  return (
     <DynamicComponent page={page} />
  )
}
</code>```

How can I achieve serverside rendering using dynamic imports?

Body:
I have a [...pageId].tsx file in the /pages directory.

In getServerSideProps, the page will check a CMS, and find a list of components to render. I want to load those components serverside, then render them out, then return the page.

Using next/dynamic like below will load the components, but it will not render them serverside. They will only stream in on the client. In other words: the customer will see 'Loading...' first, then the component renders. That's not what I want, also not for SEO.

const getDynamicComponent = (c) => dynamic(() => import(`../../components/${c}`), {
  loading: () =>
Loading...
,
  ssr: true
});

export default function SomePage({page}) {
  // Load dynamic component if necessary
  let DynamicComponent = getDynamicComponent(page.reactComponent);
  }
  return (
     <DynamicComponent page={page} />
  )
}

How can I achieve serverside rendering using dynamic imports?


问:
Selenium Actions class dragAndDrop process get stuck when try to element drop
I‘m trying to do drag and drop scenario in a list of elements.Currently I’m using Actions class to do the job, but it’s hang the process when trying to drop the element to the target position.

I’ve tried following solutions so far,

dragAndDrop(source,target)

clickAndHold(source) , release(target) - here release not happened until manually do the mouse movement.

Javascripts dragAndDrops not worked in the application

Robot class - not getting the exact element position in the local machine plus in the servers.

As my guess best way to do this from actions class , Any solution for doing  clickAndHold and once release function called do the mouseMovement from automation.It will hang the process inside the release function. And moveToElement will not work as well.


问:
Applying Unity quaternions / Euler Angle rotation to vectors for data analysis sanity/logic check
Backstory:
I'm currently writing a thesis where I am looking at the difference of movements in reality and VR. To do this I've attached a Vive Tracker to the people and tracked their head location and orientation (both in quaternions and Euler angles(EA)).

I would like to visualise the movement trajectories using the angles around the X and Y axis.
(Z is aimed away from the looking direction, Y is up and X is sideways).

My current approach:

I've had users look at a certain spot for some time to calibrate, this vector should be approximately along the negative Z axis.

Due to the way the tracker was fixed to the person it is pitching downwards. How much depends on the person. I transform the quaternions & EA to a rotation matrix for each calibration timestep and take the average over all calibration timesteps, and apply this to the three normal vectors along the three axis. I get three new vectors which define the orientation of the tracker. To account for the pitch of the tracker I calculate the vector of where the plane spanned by the X and Z coordinate system vectors and the plane spanned by the trackers own Z and Y vectors. This is the pointing vector. (There are some bugs/features where the tracker randomly switches the coordinate system, so I'm only 90% sure the coordinate system is right, the results do seem close enough.)
Applying the inverse calibration rotation matrix should yield a vector for me to apply future rotations which should then yield vectors pointing in the direction the person was pointing their head at.

So far so good, I've done this using both quaternions and the EA, which are close enough in results, yet still worringly different... Also, for one the z vector is somehow inversed. I guess one mistake somewhere with a minus or rotation convention somewhere that I can not find, but that's not the main issue.

This is the code I used for calibration:

Using Quaternions:

```<code>#Calibration RB

c0 <- 1;
calw <- 0;
calx <- 0;
caly <- 0;
calz <- 0;

C <- c(c(0,0,0),c(0,0,0),c(0,0,0));

while (dataRB$Phase[c0] == "Calibration") {
  calw <- dataRB$wquat[c0]# + calw;
  calx <- dataRB$xquat[c0]# + calx;
  caly <- dataRB$yquat[c0]# + caly;
  calz <- dataRB$zquat[c0]# + calz;
  c0 <- c0+1;

# q0 <- calw#/(c0-1);
# q1 <- calx#/(c0-1);
# q2 <- caly#/(c0-1);
# q3 <- calz#/(c0-1);

q0 <- calw#/(c0-1);
q1 <- -calx#/(c0-1);
q2 <- -calz#/(c0-1);
q3 <- -caly#/(c0-1);

# First row of the rotation matrix
r00 <- 2 * (q0 * q0 + q1 * q1) - 1;
r01 <- 2 * (q1 * q2 - q0 * q3);
r02 <- 2 * (q1 * q3 + q0 * q2);

# Second row of the rotation matrix
r10 <- 2 * (q1 * q2 + q0 * q3);
r11 <- 2 * (q0 * q0 + q2 * q2) - 1;
r12 <- 2 * (q2 * q3 - q0 * q1);

# Third row of the rotation matrix
r20 <- 2 * (q1 * q3 - q0 * q2);
r21 <- 2 * (q2 * q3 + q0 * q1);
r22 <- 2 * (q0 * q0 + q3 * q3) - 1;

# 3x3 rotation matrix
C <- C + c(c(r00, r01, r02),c(r10, r11, r12),c(r20, r21, r22));
}
C <- C/(c0-1);
calquat <- matrix(C,nrow=3,ncol=3);
# print(c0);
# print("calquat");
# print(calquat);
calquatinv <- inv(calquat);

  X_n <- c(1,0,0);
  Y_n <- c(0,1,0);
  Z_n <- c(0,0,1);

  Px <- c(calquat[1,1]*X_n[1]+calquat[1,2]*X_n[2]+calquat[1,3]*X_n[3],calquat[2,1]*X_n[1]+calquat[2,2]*X_n[2]+calquat[2,3]*X_n[3],calquat[3,1]*X_n[1]+calquat[3,2]*X_n[2]+calquat[3,3]*X_n[3]);
  Py <- c(calquat[1,1]*Y_n[1]+calquat[1,2]*Y_n[2]+calquat[1,3]*Y_n[3],calquat[2,1]*Y_n[1]+calquat[2,2]*Y_n[2]+calquat[2,3]*Y_n[3],calquat[3,1]*Y_n[1]+calquat[3,2]*Y_n[2]+calquat[3,3]*Y_n[3]);
  Pz <- c(calquat[1,1]*Z_n[1]+calquat[1,2]*Z_n[2]+calquat[1,3]*Z_n[3],calquat[2,1]*Z_n[1]+calquat[2,2]*Z_n[2]+calquat[2,3]*Z_n[3],calquat[3,1]*Z_n[1]+calquat[3,2]*Z_n[2]+calquat[3,3]*Z_n[3]);

 N <- c((Y_n[2]*Px[3]) - (Y_n[3]*Px[2]), (Y_n[3]*Px[1]) - (Y_n[1]*Px[3]), (Y_n[1]*Px[2]) - (Y_n[2]*Px[1]))
 #N <- c(0,0,1)

  Pn <- c(calquatinv[1,1]*N[1]+calquatinv[1,2]*N[2]+calquatinv[1,3]*N[3],calquatinv[2,1]*N[1]+calquatinv[2,2]*N[2]+calquatinv[2,3]*N[3],calquatinv[3,1]*N[1]+calquatinv[3,2]*N[2]+calquatinv[3,3]*N[3]);

basismatrix1 <- matrix(c(c((Y_n[2]*N[3]) - (Y_n[3]*N[2]), (Y_n[3]*N[1]) - (Y_n[1]*N[3]), (Y_n[1]*N[2]) - (Y_n[2]*N[1])),c(0,1,0),c(N[1],N[2],N[3])),nrow=3,ncol=3);

basismatrix1 <- t(basismatrix1)
</code>```

Using EA:

```<code> xrot <- 0
  yrot <- 0
  zrot <- 0

  R <- matrix(0,nrow=3,ncol=3)

  c0 <- 1

while (dataRB$Phase[c0] == "Calibration") {
  xrot <- dataRB$xrot[c0]/180*pi-pi + xrot;
  yrot <- dataRB$yrot[c0]/180*pi-pi + yrot;
  zrot <- dataRB$zrot[c0]/180*pi-pi + zrot;
  c0 <- c0+1;
}
  a <- xrot/(c0-1)
  b <- yrot/(c0-1)
  c <- zrot/(c0-1)

  # a <- 0
  # b <- 0
  # c <- 0

  Rx <- matrix(c(c(1,0,0),c(0,cos(a),-sin(a)),c(0,sin(a),cos(a))),nrow=3,ncol=3)

  Ry <- matrix(c(c(cos(b),0,sin(b)),c(0,1,0),c(-sin(b),0,cos(b))),nrow=3,ncol=3)

  Rz <- matrix(c(c(cos(c),-sin(c),0),c(sin(c),cos(c),0),c(0,0,1)),nrow=3,ncol=3)

  R <- Ry%*%Rx%*%Rz# + R;

#}

  #R <- R/(c0-1)

  Rinv <- inv(R)

  X_n <- c(1,0,0);
  Y_n <- c(0,1,0);
  Z_n <- c(0,0,1);

  Px <- c(R[1,1]*X_n[1]+R[1,2]*X_n[2]+R[1,3]*X_n[3],R[2,1]*X_n[1]+R[2,2]*X_n[2]+R[2,3]*X_n[3],R[3,1]*X_n[1]+R[3,2]*X_n[2]+R[3,3]*X_n[3]);
  Py <- c(R[1,1]*Y_n[1]+R[1,2]*Y_n[2]+R[1,3]*Y_n[3],R[2,1]*Y_n[1]+R[2,2]*Y_n[2]+R[2,3]*Y_n[3],R[3,1]*Y_n[1]+R[3,2]*Y_n[2]+R[3,3]*Y_n[3]);
  Pz <- c(R[1,1]*Z_n[1]+R[1,2]*Z_n[2]+R[1,3]*Z_n[3],R[2,1]*Z_n[1]+R[2,2]*Z_n[2]+R[2,3]*Z_n[3],R[3,1]*Z_n[1]+R[3,2]*Z_n[2]+R[3,3]*Z_n[3]);

 N <- c((Y_n[2]*Px[3]) - (Y_n[3]*Px[2]), (Y_n[3]*Px[1]) - (Y_n[1]*Px[3]), (Y_n[1]*Px[2]) - (Y_n[2]*Px[1]))
 #N <- c(0,0,1)

  Pn <- c(Rinv[1,1]*N[1]+Rinv[1,2]*N[2]+Rinv[1,3]*N[3],Rinv[2,1]*N[1]+Rinv[2,2]*N[2]+Rinv[2,3]*N[3],Rinv[3,1]*N[1]+Rinv[3,2]*N[2]+Rinv[3,3]*N[3]);

  basismatrix2 <- matrix(c(c((Y_n[2]*N[3]) - (Y_n[3]*N[2]), (Y_n[3]*N[1]) - (Y_n[1]*N[3]), (Y_n[1]*N[2]) - (Y_n[2]*N[1])),c(0,1,0),c(N[1],N[2],N[3])),nrow=3,ncol=3);

  basismatrix2 <- t(basismatrix2)
</code>```

To calculate my two vectors I calculate the pitch between the pointing vector and its projection on the Z-X plane. This yields the pitch. If the Y component of the pointer is negative, I then make the angle negative. For the yaw (rotation around the Y axis) I simply calcualte the angle between the calibrated pointer (which lies in the X-Z plane) and the pointer vector projected on the X-Z plane. Again, if X component of the pointer is smaller than x component of the calibration pointer, I make the angle negative.

Using Quaternions:

```<code>c1 <- 1

while (c1 < nrow(dataRB)+1) {

  # q0 <- dataRB$wquat[c1];
  # q1 <- dataRB$xquat[c1];
  # q2 <- dataRB$yquat[c1];
  # q3 <- dataRB$zquat[c1];

q0 <- dataRB$wquat[c1];
q1 <- -dataRB$xquat[c1];
q2 <- -dataRB$zquat[c1];
q3 <- -dataRB$yquat[c1];

  # First row of the rotation matrix
  r00 <- 2 * (q0 * q0 + q1 * q1) - 1;
  r01 <- 2 * (q1 * q2 - q0 * q3);
  r02 <- 2 * (q1 * q3 + q0 * q2);

  # Second row of the rotation matrix
  r10 <- 2 * (q1 * q2 + q0 * q3);
  r11 <- 2 * (q0 * q0 + q2 * q2) - 1;
  r12 <- 2 * (q2 * q3 - q0 * q1);

  # Third row of the rotation matrix
  r20 <- 2 * (q1 * q3 - q0 * q2);
  r21 <- 2 * (q2 * q3 + q0 * q1);
  r22 <- 2 * (q0 * q0 + q3 * q3) - 1;

  # 3x3 rotation matrix
  C <- c(c(r00, r01, r02),c(r10, r11, r12),c(r20, r21, r22));
  rot_Matrix = matrix(C,nrow=3,ncol=3);

  Pnt <- c(rot_Matrix[1,1]*Pn[1]+rot_Matrix[1,2]*Pn[2]+rot_Matrix[1,3]*Pn[3],rot_Matrix[2,1]*Pn[1]+rot_Matrix[2,2]*Pn[2]+rot_Matrix[2,3]*Pn[3],rot_Matrix[3,1]*Pn[1]+rot_Matrix[3,2]*Pn[2]+rot_Matrix[3,3]*Pn[3]);

  yaw <- -(acos((Pnt[1]*N[1]+0+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]+N[3]*N[3]))))/pi*180;
  pitch <- (acos((Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3]))))/pi*180;
  #pitch2 <- (atan(Pnt[2]/sqrt(Pnt[1]^2+Pnt[3]^2)))/pi*180;
  #angle <- (acos((Pnt[1]*N[1]+Pnt[2]*N[2]+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]*N[2]*N[2]+N[3]*N[3]))))/pi*180;

  if(Pnt[2] < 0){
    pitch <- -pitch
  }
  if(Pnt[1] < N[1]){
    yaw <- -yaw
  }

  dataRB$pitch[c1] = round(pitch,7)
  dataRB$yaw[c1] = round(yaw,7)
  #dataRB$angle[c1] = round(angle,7)

  dataRB$Px[c1] = round(Pnt[1],7)
  dataRB$Py[c1] = round(Pnt[2],7)
  dataRB$Pz[c1] = round(Pnt[3],7)

  #dataRB$pitch2[c1] = round(pitch2,7)

  if(c1 > 2){

  P_pre <- c(dataRB$Px[c1-2],dataRB$Py[c1-2],dataRB$Pz[c1-2]);
  P_current <- c(dataRB$Px[c1-1],dataRB$Py[c1-1],dataRB$Pz[c1-1]);
  P_post <- c(dataRB$Px[c1],dataRB$Py[c1],dataRB$Pz[c1]);

  #print(P_pre);
  #print(P_current);
  #print(P_post);

  T_pre <- c(dataRB$Time[c1-2]);
  T_current <- c(dataRB$Time[c1-1]);
  T_post <- c(dataRB$Time[c1]);

  #print(T_pre);
  #print(T_current);
  #print(T_post);

  suppressWarnings(preangle <- acos( sum(P_pre*P_current) / ( sqrt(sum(P_pre * P_pre)) * sqrt(sum(P_current * P_current)))))

  suppressWarnings(postangle <- acos(sum(P_pre*P_post) / ( sqrt(sum(P_current * P_current)) * sqrt(sum(P_post * P_post)))))

  #print(preangle);
  #print(postangle);

  preangle <- preangle/pi*180;
  postangle <- postangle/pi*180;

  #dataRB$angle[c1-1] <- preangle;

  #print("angles");
  #print(preangle);
  #print(postangle);

  #print("timesteps");
  #print(T_current-T_pre);
  #print(T_post-T_current);

  V <- (preangle/(T_current-T_pre)+postangle/(T_post-T_current))/2;

  dataRB$V[c1-1] <- round(V,7);

  #print("V");
  #print(dataRB$V[c1-1]);

  #dataRB$preangle[c1-1] <- preangle;
  #dataRB$postangle[c1-1] <- postangle;
  #dataRB$timestep_pre[c1-1] <- (T_current-T_pre);
  #dataRB$timestep_post[c1-1] <- (T_post-T_current);

  if(c1 > 3){
    dataRB$Va[c1-2] <- round(((dataRB$V[c1-2]-dataRB$V[c1-3])/(dataRB$Time[c1-2]-dataRB$Time[c1-3])+(dataRB$V[c1-1]-dataRB$V[c1-2])/(dataRB$Time[c1-1]-dataRB$Time[c1-2]))/2,7);
  }

  # if(is.nan(preangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  #
  # if(is.nan(postangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  }

c1 <- c1 + 1;

}
</code>```

Using EA:

```<code>c1 <- 1

while (c1 < nrow(dataRB)+1) {

  xrot <- dataRB$xrot[c1]/180*pi# + xrot;
  yrot <- dataRB$yrot[c1]/180*pi# + yrot;
  zrot <- dataRB$zrot[c1]/180*pi# + zrot;

  a <- xrot-pi#/(c0-1)
  b <- yrot-pi#/(c0-1)
  c <- zrot-pi#/(c0-1)

  Rx <- matrix(c(c(1,0,0),c(0,cos(a),-sin(a)),c(0,sin(a),cos(a))),nrow=3,ncol=3)

  Ry <- matrix(c(c(cos(b),0,sin(b)),c(0,1,0),c(-sin(b),0,cos(b))),nrow=3,ncol=3)

  Rz <- matrix(c(c(cos(c),-sin(c),0),c(sin(c),cos(c),0),c(0,0,1)),nrow=3,ncol=3)

  R <- Ry%*%Rx%*%Rz;

  #R <- matrix(c(c()))

  #EA <- c(a,b,c)

  #R2 <- EA2DCM(EA,"yxz")

  rot_Matrix = R;

Pnt <- c(rot_Matrix[1,1]*Pn[1]+rot_Matrix[1,2]*Pn[2]+rot_Matrix[1,3]*Pn[3],rot_Matrix[2,1]*Pn[1]+rot_Matrix[2,2]*Pn[2]+rot_Matrix[2,3]*Pn[3],rot_Matrix[3,1]*Pn[1]+rot_Matrix[3,2]*Pn[2]+rot_Matrix[3,3]*Pn[3]);

  yaw <- (acos((Pnt[1]*N[1]+0+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]+N[3]*N[3]))))/pi*180;
  pitch <- (acos((Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3]))))/pi*180;
  #pitch2 <- (atan(Pnt[2]/sqrt(Pnt[1]^2+Pnt[3]^2)))/pi*180;

  #angle <- (acos((Pnt[1]*N[1]+Pnt[2]*N[2]+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]*N[2]*N[2]+N[3]*N[3]))))/pi*180;

  if(Pnt[2] < 0){
    pitch <- -pitch
  }

  if(Pnt[1] < 0){
    yaw <- -yaw
  }

  dataRB$pitch2[c1] = round(pitch,7)
  dataRB$yaw2[c1] = round(yaw,7)
  #dataRB$angle2[c1] = round(angle,7)

  dataRB$P2x[c1] = round(Pnt[1],7)
  dataRB$P2y[c1] = round(Pnt[2],7)
  dataRB$P2z[c1] = round(Pnt[3],7)

  if(c1 > 2){

  P_pre <- c(dataRB$P2x[c1-2],dataRB$P2y[c1-2],dataRB$P2z[c1-2]);
  P_current <- c(dataRB$P2x[c1-1],dataRB$P2y[c1-1],dataRB$P2z[c1-1]);
  P_post <- c(dataRB$P2x[c1],dataRB$P2y[c1],dataRB$P2z[c1]);

  #print(P_pre);
  #print(P_current);
  #print(P_post);

  T_pre <- c(dataRB$Time[c1-2]);
  T_current <- c(dataRB$Time[c1-1]);
  T_post <- c(dataRB$Time[c1]);

  #print(T_pre);
  #print(T_current);
  #print(T_post);

  suppressWarnings(preangle <- acos( sum(P_pre*P_current) / ( sqrt(sum(P_pre * P_pre)) * sqrt(sum(P_current * P_current)))))

  suppressWarnings(postangle <- acos(sum(P_pre*P_post) / ( sqrt(sum(P_current * P_current)) * sqrt(sum(P_post * P_post)))))

  #print(preangle);
  #print(postangle);

  preangle <- preangle/pi*180;
  postangle <- postangle/pi*180;

  #dataRB$angle[c1-1] <- preangle;

  #print("angles");
  #print(preangle);
  #print(postangle);

  #print("timesteps");
  #print(T_current-T_pre);
  #print(T_post-T_current);

  V <- (preangle/(T_current-T_pre)+postangle/(T_post-T_current))/2;

  dataRB$V2[c1-1] <- round(V,7);

  #print("V");
  #print(dataRB$V[c1-1]);

  #dataRB$preangle[c1-1] <- preangle;
  #dataRB$postangle[c1-1] <- postangle;
  #dataRB$timestep_pre[c1-1] <- (T_current-T_pre);
  #dataRB$timestep_post[c1-1] <- (T_post-T_current);

  if(c1 > 3){
    dataRB$V2a[c1-2] <- round(((dataRB$V2[c1-2]-dataRB$V2[c1-3])/(dataRB$Time[c1-2]-dataRB$Time[c1-3])+(dataRB$V2[c1-1]-dataRB$V2[c1-2])/(dataRB$Time[c1-1]-dataRB$Time[c1-2]))/2,7);
  }

  # if(is.nan(preangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  #
  # if(is.nan(postangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  }

c1 <- c1 + 1;

}
</code>```

I've been using RStudio to do this (and have already surpassed the labs monthly computing time working on this). Now my results make somewhat sense for all the rotations below 45 degrees, however, for what should be approximately a 90 degree rotation I do get a pitch of -40 degrees. It seems possible, but unrealistic. I am not sure if this was the case. The user study had over 30 participants, I can't recall all their movements.

If anybody would be so kind to logic check my logic and if somebody is motivated to further dive in to this issue and maybe help me out by pointing out potential errors in my code, please feel free.
The github repository is open and can be found here: https://github.com/NicK4rT/Unity-Projects/tree/main/Recordings
It includes all the datasets used and the analysis rstudio code in the Recordings folder. (Analysis.qmd is the code).

I've also attached the complete code used to import, tidy and transform the first 27 data sets. It is three times the same code, but for the three different types of data sets.

Link to data set I used for testing before running the code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Sorting/US1RB.csv
Resulting data set after running the code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Clean/US1RB.csv

Complete analysis code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Analysis.qmd (too long to include in this post)

Conclusion:

To answer questions: Yes my code is bad and messy, I'm sorry about that. I should feel bad and I do feel bad.
Furthermore, why didn't I just raycast and calculate the voctor directly in unity? Because I'm stupid and didn't think it was needed and sadly I didn't have the time to properly test everything as I had to also implement eye tracking before the study. I just didn't know better and now I'm in this analysis mess with a deadline approaching fast. Lessons learned.

Any help is appreciated. I can't tell what makes sense anymore.

Body:
Backstory:
I'm currently writing a thesis where I am looking at the difference of movements in reality and VR. To do this I've attached a Vive Tracker to the people and tracked their head location and orientation (both in quaternions and Euler angles(EA)).

I would like to visualise the movement trajectories using the angles around the X and Y axis.
(Z is aimed away from the looking direction, Y is up and X is sideways).

My current approach:

I've had users look at a certain spot for some time to calibrate, this vector should be approximately along the negative Z axis.

Due to the way the tracker was fixed to the person it is pitching downwards. How much depends on the person. I transform the quaternions & EA to a rotation matrix for each calibration timestep and take the average over all calibration timesteps, and apply this to the three normal vectors along the three axis. I get three new vectors which define the orientation of the tracker. To account for the pitch of the tracker I calculate the vector of where the plane spanned by the X and Z coordinate system vectors and the plane spanned by the trackers own Z and Y vectors. This is the pointing vector. (There are some bugs/features where the tracker randomly switches the coordinate system, so I'm only 90% sure the coordinate system is right, the results do seem close enough.)
Applying the inverse calibration rotation matrix should yield a vector for me to apply future rotations which should then yield vectors pointing in the direction the person was pointing their head at.

So far so good, I've done this using both quaternions and the EA, which are close enough in results, yet still worringly different... Also, for one the z vector is somehow inversed. I guess one mistake somewhere with a minus or rotation convention somewhere that I can not find, but that's not the main issue.

This is the code I used for calibration:

Using Quaternions:

#Calibration RB

c0 <- 1;
calw <- 0;
calx <- 0;
caly <- 0;
calz <- 0;

C <- c(c(0,0,0),c(0,0,0),c(0,0,0));

while (dataRB$Phase[c0] == "Calibration") {
  calw <- dataRB$wquat[c0]# + calw;
  calx <- dataRB$xquat[c0]# + calx;
  caly <- dataRB$yquat[c0]# + caly;
  calz <- dataRB$zquat[c0]# + calz;
  c0 <- c0+1;

# q0 <- calw#/(c0-1);
# q1 <- calx#/(c0-1);
# q2 <- caly#/(c0-1);
# q3 <- calz#/(c0-1);

q0 <- calw#/(c0-1);
q1 <- -calx#/(c0-1);
q2 <- -calz#/(c0-1);
q3 <- -caly#/(c0-1);

# First row of the rotation matrix
r00 <- 2 * (q0 * q0 + q1 * q1) - 1;
r01 <- 2 * (q1 * q2 - q0 * q3);
r02 <- 2 * (q1 * q3 + q0 * q2);

# Second row of the rotation matrix
r10 <- 2 * (q1 * q2 + q0 * q3);
r11 <- 2 * (q0 * q0 + q2 * q2) - 1;
r12 <- 2 * (q2 * q3 - q0 * q1);

# Third row of the rotation matrix
r20 <- 2 * (q1 * q3 - q0 * q2);
r21 <- 2 * (q2 * q3 + q0 * q1);
r22 <- 2 * (q0 * q0 + q3 * q3) - 1;

# 3x3 rotation matrix
C <- C + c(c(r00, r01, r02),c(r10, r11, r12),c(r20, r21, r22));
}
C <- C/(c0-1);
calquat <- matrix(C,nrow=3,ncol=3);
# print(c0);
# print("calquat");
# print(calquat);
calquatinv <- inv(calquat);

  X_n <- c(1,0,0);
  Y_n <- c(0,1,0);
  Z_n <- c(0,0,1);

  Px <- c(calquat[1,1]*X_n[1]+calquat[1,2]*X_n[2]+calquat[1,3]*X_n[3],calquat[2,1]*X_n[1]+calquat[2,2]*X_n[2]+calquat[2,3]*X_n[3],calquat[3,1]*X_n[1]+calquat[3,2]*X_n[2]+calquat[3,3]*X_n[3]);
  Py <- c(calquat[1,1]*Y_n[1]+calquat[1,2]*Y_n[2]+calquat[1,3]*Y_n[3],calquat[2,1]*Y_n[1]+calquat[2,2]*Y_n[2]+calquat[2,3]*Y_n[3],calquat[3,1]*Y_n[1]+calquat[3,2]*Y_n[2]+calquat[3,3]*Y_n[3]);
  Pz <- c(calquat[1,1]*Z_n[1]+calquat[1,2]*Z_n[2]+calquat[1,3]*Z_n[3],calquat[2,1]*Z_n[1]+calquat[2,2]*Z_n[2]+calquat[2,3]*Z_n[3],calquat[3,1]*Z_n[1]+calquat[3,2]*Z_n[2]+calquat[3,3]*Z_n[3]);

 N <- c((Y_n[2]*Px[3]) - (Y_n[3]*Px[2]), (Y_n[3]*Px[1]) - (Y_n[1]*Px[3]), (Y_n[1]*Px[2]) - (Y_n[2]*Px[1]))
 #N <- c(0,0,1)

  Pn <- c(calquatinv[1,1]*N[1]+calquatinv[1,2]*N[2]+calquatinv[1,3]*N[3],calquatinv[2,1]*N[1]+calquatinv[2,2]*N[2]+calquatinv[2,3]*N[3],calquatinv[3,1]*N[1]+calquatinv[3,2]*N[2]+calquatinv[3,3]*N[3]);

basismatrix1 <- matrix(c(c((Y_n[2]*N[3]) - (Y_n[3]*N[2]), (Y_n[3]*N[1]) - (Y_n[1]*N[3]), (Y_n[1]*N[2]) - (Y_n[2]*N[1])),c(0,1,0),c(N[1],N[2],N[3])),nrow=3,ncol=3);

basismatrix1 <- t(basismatrix1)

Using EA:

 xrot <- 0
  yrot <- 0
  zrot <- 0

  R <- matrix(0,nrow=3,ncol=3)

  c0 <- 1

while (dataRB$Phase[c0] == "Calibration") {
  xrot <- dataRB$xrot[c0]/180*pi-pi + xrot;
  yrot <- dataRB$yrot[c0]/180*pi-pi + yrot;
  zrot <- dataRB$zrot[c0]/180*pi-pi + zrot;
  c0 <- c0+1;
}
  a <- xrot/(c0-1)
  b <- yrot/(c0-1)
  c <- zrot/(c0-1)

  # a <- 0
  # b <- 0
  # c <- 0

  Rx <- matrix(c(c(1,0,0),c(0,cos(a),-sin(a)),c(0,sin(a),cos(a))),nrow=3,ncol=3)

  Ry <- matrix(c(c(cos(b),0,sin(b)),c(0,1,0),c(-sin(b),0,cos(b))),nrow=3,ncol=3)

  Rz <- matrix(c(c(cos(c),-sin(c),0),c(sin(c),cos(c),0),c(0,0,1)),nrow=3,ncol=3)

  R <- Ry%*%Rx%*%Rz# + R;

#}

  #R <- R/(c0-1)

  Rinv <- inv(R)

  X_n <- c(1,0,0);
  Y_n <- c(0,1,0);
  Z_n <- c(0,0,1);

  Px <- c(R[1,1]*X_n[1]+R[1,2]*X_n[2]+R[1,3]*X_n[3],R[2,1]*X_n[1]+R[2,2]*X_n[2]+R[2,3]*X_n[3],R[3,1]*X_n[1]+R[3,2]*X_n[2]+R[3,3]*X_n[3]);
  Py <- c(R[1,1]*Y_n[1]+R[1,2]*Y_n[2]+R[1,3]*Y_n[3],R[2,1]*Y_n[1]+R[2,2]*Y_n[2]+R[2,3]*Y_n[3],R[3,1]*Y_n[1]+R[3,2]*Y_n[2]+R[3,3]*Y_n[3]);
  Pz <- c(R[1,1]*Z_n[1]+R[1,2]*Z_n[2]+R[1,3]*Z_n[3],R[2,1]*Z_n[1]+R[2,2]*Z_n[2]+R[2,3]*Z_n[3],R[3,1]*Z_n[1]+R[3,2]*Z_n[2]+R[3,3]*Z_n[3]);

 N <- c((Y_n[2]*Px[3]) - (Y_n[3]*Px[2]), (Y_n[3]*Px[1]) - (Y_n[1]*Px[3]), (Y_n[1]*Px[2]) - (Y_n[2]*Px[1]))
 #N <- c(0,0,1)

  Pn <- c(Rinv[1,1]*N[1]+Rinv[1,2]*N[2]+Rinv[1,3]*N[3],Rinv[2,1]*N[1]+Rinv[2,2]*N[2]+Rinv[2,3]*N[3],Rinv[3,1]*N[1]+Rinv[3,2]*N[2]+Rinv[3,3]*N[3]);

  basismatrix2 <- matrix(c(c((Y_n[2]*N[3]) - (Y_n[3]*N[2]), (Y_n[3]*N[1]) - (Y_n[1]*N[3]), (Y_n[1]*N[2]) - (Y_n[2]*N[1])),c(0,1,0),c(N[1],N[2],N[3])),nrow=3,ncol=3);

  basismatrix2 <- t(basismatrix2)

To calculate my two vectors I calculate the pitch between the pointing vector and its projection on the Z-X plane. This yields the pitch. If the Y component of the pointer is negative, I then make the angle negative. For the yaw (rotation around the Y axis) I simply calcualte the angle between the calibrated pointer (which lies in the X-Z plane) and the pointer vector projected on the X-Z plane. Again, if X component of the pointer is smaller than x component of the calibration pointer, I make the angle negative.

Using Quaternions:

c1 <- 1

while (c1 < nrow(dataRB)+1) {

  # q0 <- dataRB$wquat[c1];
  # q1 <- dataRB$xquat[c1];
  # q2 <- dataRB$yquat[c1];
  # q3 <- dataRB$zquat[c1];

q0 <- dataRB$wquat[c1];
q1 <- -dataRB$xquat[c1];
q2 <- -dataRB$zquat[c1];
q3 <- -dataRB$yquat[c1];

  # First row of the rotation matrix
  r00 <- 2 * (q0 * q0 + q1 * q1) - 1;
  r01 <- 2 * (q1 * q2 - q0 * q3);
  r02 <- 2 * (q1 * q3 + q0 * q2);

  # Second row of the rotation matrix
  r10 <- 2 * (q1 * q2 + q0 * q3);
  r11 <- 2 * (q0 * q0 + q2 * q2) - 1;
  r12 <- 2 * (q2 * q3 - q0 * q1);

  # Third row of the rotation matrix
  r20 <- 2 * (q1 * q3 - q0 * q2);
  r21 <- 2 * (q2 * q3 + q0 * q1);
  r22 <- 2 * (q0 * q0 + q3 * q3) - 1;

  # 3x3 rotation matrix
  C <- c(c(r00, r01, r02),c(r10, r11, r12),c(r20, r21, r22));
  rot_Matrix = matrix(C,nrow=3,ncol=3);

  Pnt <- c(rot_Matrix[1,1]*Pn[1]+rot_Matrix[1,2]*Pn[2]+rot_Matrix[1,3]*Pn[3],rot_Matrix[2,1]*Pn[1]+rot_Matrix[2,2]*Pn[2]+rot_Matrix[2,3]*Pn[3],rot_Matrix[3,1]*Pn[1]+rot_Matrix[3,2]*Pn[2]+rot_Matrix[3,3]*Pn[3]);

  yaw <- -(acos((Pnt[1]*N[1]+0+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]+N[3]*N[3]))))/pi*180;
  pitch <- (acos((Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3]))))/pi*180;
  #pitch2 <- (atan(Pnt[2]/sqrt(Pnt[1]^2+Pnt[3]^2)))/pi*180;
  #angle <- (acos((Pnt[1]*N[1]+Pnt[2]*N[2]+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]*N[2]*N[2]+N[3]*N[3]))))/pi*180;

  if(Pnt[2] < 0){
    pitch <- -pitch
  }
  if(Pnt[1] < N[1]){
    yaw <- -yaw
  }

  dataRB$pitch[c1] = round(pitch,7)
  dataRB$yaw[c1] = round(yaw,7)
  #dataRB$angle[c1] = round(angle,7)

  dataRB$Px[c1] = round(Pnt[1],7)
  dataRB$Py[c1] = round(Pnt[2],7)
  dataRB$Pz[c1] = round(Pnt[3],7)

  #dataRB$pitch2[c1] = round(pitch2,7)

  if(c1 > 2){

  P_pre <- c(dataRB$Px[c1-2],dataRB$Py[c1-2],dataRB$Pz[c1-2]);
  P_current <- c(dataRB$Px[c1-1],dataRB$Py[c1-1],dataRB$Pz[c1-1]);
  P_post <- c(dataRB$Px[c1],dataRB$Py[c1],dataRB$Pz[c1]);

  #print(P_pre);
  #print(P_current);
  #print(P_post);

  T_pre <- c(dataRB$Time[c1-2]);
  T_current <- c(dataRB$Time[c1-1]);
  T_post <- c(dataRB$Time[c1]);

  #print(T_pre);
  #print(T_current);
  #print(T_post);

  suppressWarnings(preangle <- acos( sum(P_pre*P_current) / ( sqrt(sum(P_pre * P_pre)) * sqrt(sum(P_current * P_current)))))

  suppressWarnings(postangle <- acos(sum(P_pre*P_post) / ( sqrt(sum(P_current * P_current)) * sqrt(sum(P_post * P_post)))))

  #print(preangle);
  #print(postangle);

  preangle <- preangle/pi*180;
  postangle <- postangle/pi*180;

  #dataRB$angle[c1-1] <- preangle;

  #print("angles");
  #print(preangle);
  #print(postangle);

  #print("timesteps");
  #print(T_current-T_pre);
  #print(T_post-T_current);

  V <- (preangle/(T_current-T_pre)+postangle/(T_post-T_current))/2;

  dataRB$V[c1-1] <- round(V,7);

  #print("V");
  #print(dataRB$V[c1-1]);

  #dataRB$preangle[c1-1] <- preangle;
  #dataRB$postangle[c1-1] <- postangle;
  #dataRB$timestep_pre[c1-1] <- (T_current-T_pre);
  #dataRB$timestep_post[c1-1] <- (T_post-T_current);

  if(c1 > 3){
    dataRB$Va[c1-2] <- round(((dataRB$V[c1-2]-dataRB$V[c1-3])/(dataRB$Time[c1-2]-dataRB$Time[c1-3])+(dataRB$V[c1-1]-dataRB$V[c1-2])/(dataRB$Time[c1-1]-dataRB$Time[c1-2]))/2,7);
  }

  # if(is.nan(preangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  #
  # if(is.nan(postangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  }

c1 <- c1 + 1;

}

Using EA:

c1 <- 1

while (c1 < nrow(dataRB)+1) {

  xrot <- dataRB$xrot[c1]/180*pi# + xrot;
  yrot <- dataRB$yrot[c1]/180*pi# + yrot;
  zrot <- dataRB$zrot[c1]/180*pi# + zrot;

  a <- xrot-pi#/(c0-1)
  b <- yrot-pi#/(c0-1)
  c <- zrot-pi#/(c0-1)

  Rx <- matrix(c(c(1,0,0),c(0,cos(a),-sin(a)),c(0,sin(a),cos(a))),nrow=3,ncol=3)

  Ry <- matrix(c(c(cos(b),0,sin(b)),c(0,1,0),c(-sin(b),0,cos(b))),nrow=3,ncol=3)

  Rz <- matrix(c(c(cos(c),-sin(c),0),c(sin(c),cos(c),0),c(0,0,1)),nrow=3,ncol=3)

  R <- Ry%*%Rx%*%Rz;

  #R <- matrix(c(c()))

  #EA <- c(a,b,c)

  #R2 <- EA2DCM(EA,"yxz")

  rot_Matrix = R;

Pnt <- c(rot_Matrix[1,1]*Pn[1]+rot_Matrix[1,2]*Pn[2]+rot_Matrix[1,3]*Pn[3],rot_Matrix[2,1]*Pn[1]+rot_Matrix[2,2]*Pn[2]+rot_Matrix[2,3]*Pn[3],rot_Matrix[3,1]*Pn[1]+rot_Matrix[3,2]*Pn[2]+rot_Matrix[3,3]*Pn[3]);

  yaw <- (acos((Pnt[1]*N[1]+0+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]+N[3]*N[3]))))/pi*180;
  pitch <- (acos((Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(Pnt[1]*Pnt[1]+Pnt[3]*Pnt[3]))))/pi*180;
  #pitch2 <- (atan(Pnt[2]/sqrt(Pnt[1]^2+Pnt[3]^2)))/pi*180;

  #angle <- (acos((Pnt[1]*N[1]+Pnt[2]*N[2]+Pnt[3]*N[3])/(sqrt(Pnt[1]*Pnt[1]+Pnt[2]*Pnt[2]+Pnt[3]*Pnt[3])*sqrt(N[1]*N[1]*N[2]*N[2]+N[3]*N[3]))))/pi*180;

  if(Pnt[2] < 0){
    pitch <- -pitch
  }

  if(Pnt[1] < 0){
    yaw <- -yaw
  }

  dataRB$pitch2[c1] = round(pitch,7)
  dataRB$yaw2[c1] = round(yaw,7)
  #dataRB$angle2[c1] = round(angle,7)

  dataRB$P2x[c1] = round(Pnt[1],7)
  dataRB$P2y[c1] = round(Pnt[2],7)
  dataRB$P2z[c1] = round(Pnt[3],7)

  if(c1 > 2){

  P_pre <- c(dataRB$P2x[c1-2],dataRB$P2y[c1-2],dataRB$P2z[c1-2]);
  P_current <- c(dataRB$P2x[c1-1],dataRB$P2y[c1-1],dataRB$P2z[c1-1]);
  P_post <- c(dataRB$P2x[c1],dataRB$P2y[c1],dataRB$P2z[c1]);

  #print(P_pre);
  #print(P_current);
  #print(P_post);

  T_pre <- c(dataRB$Time[c1-2]);
  T_current <- c(dataRB$Time[c1-1]);
  T_post <- c(dataRB$Time[c1]);

  #print(T_pre);
  #print(T_current);
  #print(T_post);

  suppressWarnings(preangle <- acos( sum(P_pre*P_current) / ( sqrt(sum(P_pre * P_pre)) * sqrt(sum(P_current * P_current)))))

  suppressWarnings(postangle <- acos(sum(P_pre*P_post) / ( sqrt(sum(P_current * P_current)) * sqrt(sum(P_post * P_post)))))

  #print(preangle);
  #print(postangle);

  preangle <- preangle/pi*180;
  postangle <- postangle/pi*180;

  #dataRB$angle[c1-1] <- preangle;

  #print("angles");
  #print(preangle);
  #print(postangle);

  #print("timesteps");
  #print(T_current-T_pre);
  #print(T_post-T_current);

  V <- (preangle/(T_current-T_pre)+postangle/(T_post-T_current))/2;

  dataRB$V2[c1-1] <- round(V,7);

  #print("V");
  #print(dataRB$V[c1-1]);

  #dataRB$preangle[c1-1] <- preangle;
  #dataRB$postangle[c1-1] <- postangle;
  #dataRB$timestep_pre[c1-1] <- (T_current-T_pre);
  #dataRB$timestep_post[c1-1] <- (T_post-T_current);

  if(c1 > 3){
    dataRB$V2a[c1-2] <- round(((dataRB$V2[c1-2]-dataRB$V2[c1-3])/(dataRB$Time[c1-2]-dataRB$Time[c1-3])+(dataRB$V2[c1-1]-dataRB$V2[c1-2])/(dataRB$Time[c1-1]-dataRB$Time[c1-2]))/2,7);
  }

  # if(is.nan(preangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  #
  # if(is.nan(postangle)){
  #   c1 <- c1-1;
  #   dataRB <- dataRB[-c(c1), ]
  # }
  }

c1 <- c1 + 1;

}

I've been using RStudio to do this (and have already surpassed the labs monthly computing time working on this). Now my results make somewhat sense for all the rotations below 45 degrees, however, for what should be approximately a 90 degree rotation I do get a pitch of -40 degrees. It seems possible, but unrealistic. I am not sure if this was the case. The user study had over 30 participants, I can't recall all their movements.

If anybody would be so kind to logic check my logic and if somebody is motivated to further dive in to this issue and maybe help me out by pointing out potential errors in my code, please feel free.
The github repository is open and can be found here: https://github.com/NicK4rT/Unity-Projects/tree/main/Recordings
It includes all the datasets used and the analysis rstudio code in the Recordings folder. (Analysis.qmd is the code).

I've also attached the complete code used to import, tidy and transform the first 27 data sets. It is three times the same code, but for the three different types of data sets.

Link to data set I used for testing before running the code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Sorting/US1RB.csv
Resulting data set after running the code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Clean/US1RB.csv

Complete analysis code: https://github.com/NicK4rT/Unity-Projects/blob/main/Recordings/Analysis.qmd (too long to include in this post)

Conclusion:

To answer questions: Yes my code is bad and messy, I'm sorry about that. I should feel bad and I do feel bad.
Furthermore, why didn't I just raycast and calculate the voctor directly in unity? Because I'm stupid and didn't think it was needed and sadly I didn't have the time to properly test everything as I had to also implement eye tracking before the study. I just didn't know better and now I'm in this analysis mess with a deadline approaching fast. Lessons learned.

Any help is appreciated. I can't tell what makes sense anymore.


问:
Camunda Object Deserialisation
I am setting LoanObj1 (simple pojo with Just STrings) and LoanObj2(complex pojo with List and Maps)
using belong code and set it in the excution.setVariable

```<code>ObjectValue objectValue = Variables.objectValue(object)
                .serializationDataFormat(Variables.SerializationDataFormats.JSON)
                .create();

</code>```

Also i am able to read both the POJO excution.getVariable in deletegate classes .But when i am trying to read

```<code>LoanObj2 loanObj2 = (LoanObj2) execution.getVariableLocal("loanObj2");
</code>```

IT works fine except when i try to read the LoanObj2 in MessageEndEvent.java class as shown below
I am able  to read LoanObj1.Also i am able to read LoanObj2 if choose ASYNCHRNOUS AFTER .But i dont want to choose ASYNCHRNOUS AFTER  as I need to execute Step 3 in background thread.
How to read LOanObj2
Error message

```<code>org.camunda.bpm.engine.ProcessEngineException:
            Cannot deserialize object in variable 'LoanObj2':
            SPIN/JACKSON-JSON-01006 Cannot deserialize '{"requestI...' to java type '[simple type, class com.LoanObj2'
</code>```

Screenshot from 2023-01-11 17-28-58|690x253

Title: Camunda Object Deserialisation

Body:
I am setting LoanObj1 (simple pojo with Just STrings) and LoanObj2(complex pojo with List and Maps)
using belong code and set it in the excution.setVariable

ObjectValue objectValue = Variables.objectValue(object)
                .serializationDataFormat(Variables.SerializationDataFormats.JSON)
                .create();

Also i am able to read both the POJO excution.getVariable in deletegate classes .But when i am trying to read

LoanObj2 loanObj2 = (LoanObj2) execution.getVariableLocal("loanObj2");

IT works fine except when i try to read the LoanObj2 in MessageEndEvent.java class as shown below
I am able  to read LoanObj1.Also i am able to read LoanObj2 if choose ASYNCHRNOUS AFTER .But i dont want to choose ASYNCHRNOUS AFTER  as I need to execute Step 3 in background thread.
How to read LOanObj2
Error message

org.camunda.bpm.engine.ProcessEngineException:
            Cannot deserialize object in variable 'LoanObj2':
            SPIN/JACKSON-JSON-01006 Cannot deserialize '{"requestI...' to java type '[simple type, class com.LoanObj2'

Screenshot from 2023-01-11 17-28-58|690x253


问:
How to distinguish connected users in WebSocket?
I'm trying to create an event in express.js, where connected users will be sent to the client.

My goal is that in client side user can see who belongs that particular message sent from.

As it describes in docs and as I could also run in localhost, broadcasting messages works fine.

```<code>wss.on("connection", function connection(ws) {

    ws.on("message", function message(data) {
        wss.clients.forEach(function each(client) {
            if (client !== ws && client.readyState === WebSocket.OPEN) {
                client.send(data);
            }
        });
    });
});
</code>```

So before sending messages to client, there should be another event where connected username should be sent, so that in client side can be defined who that particular message belongs.

My idea is to create users object which supposed to keep track of all connected users like here.

```<code>const users = {};
wss.on("connection", function connection(ws) {
    ws.on("userName", function message(userName) {//this doesn't work
          const user = {
            name: userName,
            id: uuid(), // some unique id, no idea if websocket has or not
          };

           users[id]= user
           ws.send("user", user) // current user who belongs the message to
           ws.send("users", users) // users to show connected users list
    });

    ws.on("message", function message(data) {
        wss.clients.forEach(function each(client) {
            if (client !== ws && client.readyState === WebSocket.OPEN) {
                client.send(data);
            }
        });
    });
});
</code>```

user event doesn't work, it is just my idea but not sure if how to do it correctly.

Any help will be appreciated.

Body:
I'm trying to create an event in express.js, where connected users will be sent to the client.

My goal is that in client side user can see who belongs that particular message sent from.

As it describes in docs and as I could also run in localhost, broadcasting messages works fine.

wss.on("connection", function connection(ws) {

    ws.on("message", function message(data) {
        wss.clients.forEach(function each(client) {
            if (client !== ws && client.readyState === WebSocket.OPEN) {
                client.send(data);
            }
        });
    });
});

So before sending messages to client, there should be another event where connected username should be sent, so that in client side can be defined who that particular message belongs.

My idea is to create users object which supposed to keep track of all connected users like here.

const users = {};
wss.on("connection", function connection(ws) {
    ws.on("userName", function message(userName) {//this doesn't work
          const user = {
            name: userName,
            id: uuid(), // some unique id, no idea if websocket has or not
          };

           users[id]= user
           ws.send("user", user) // current user who belongs the message to
           ws.send("users", users) // users to show connected users list
    });

    ws.on("message", function message(data) {
        wss.clients.forEach(function each(client) {
            if (client !== ws && client.readyState === WebSocket.OPEN) {
                client.send(data);
            }
        });
    });
});

user event doesn't work, it is just my idea but not sure if how to do it correctly.

Any help will be appreciated.


问:
Find definition of the 'action' inside 'data' object in jquery
I'm a back-end dev that inherited code that looks like this

```<code>            xhr =  jQuery.ajax({

                        type: 'POST',
                        url: ajax_url,  // ERROR!!
                        dataType: "json",
                        data:  {
                                    action: 'properties', <---------------------------------
                                    data: url_vars,
                                    url: document.URL
                                },
</code>```

I know that the action called properties has to be defined somewhere, but I'm not sure how to find it.

I read multiple threads on SO, but this is not a form action, so I'm not sure how one would go about finding it. If an experienced front-end dev saw this name, what would they look for specifically inside the code?

Apologies for the newbie question, but this is a bit confusing.

Closest answer I found is the data.action is an attribute action of the object data is a value that you known cos we haven't any reference, unfortunately I'm not even sure where to look for any reference apart from analyzing 1000+ times the word 'properties' is mentioned in the framework's code.

Any help is greatly appreciated.

Body:
I'm a back-end dev that inherited code that looks like this

            xhr =  jQuery.ajax({

                        type: 'POST',
                        url: ajax_url,  // ERROR!!
                        dataType: "json",
                        data:  {
                                    action: 'properties', <---------------------------------
                                    data: url_vars,
                                    url: document.URL
                                },

I know that the action called properties has to be defined somewhere, but I'm not sure how to find it.

I read multiple threads on SO, but this is not a form action, so I'm not sure how one would go about finding it. If an experienced front-end dev saw this name, what would they look for specifically inside the code?

Apologies for the newbie question, but this is a bit confusing.

Closest answer I found is the data.action is an attribute action of the object data is a value that you known cos we haven't any reference, unfortunately I'm not even sure where to look for any reference apart from analyzing 1000+ times the word 'properties' is mentioned in the framework's code.

Any help is greatly appreciated.


问:
Python logging use a single logger for entire project where name is defined by arguments from cmd
Hey I am trying to set up a logger for python3.9 for an entire project, with multiple files. I want to just define the logger in main.py using command line arguments to define log file name.

```<code>logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level='INFO')
logger = logging.getLogger(__name__)

def main():

file_name = sys.argv[1]
lookback_minutes = int(sys.argv[2])
file_handler = logging.FileHandler(f'log/{file_name}.log')
logger.addHandler(file_handler)
logger.info(f'Running processing chain for: {file_name}')
processing_chain.run(lookback_minutes)
</code>```

processing_chain file:

```<code>import logging

def run(lookback_minutes):
    logging.info(lookback_minutes)
</code>```

Which works for main, I get the info statement printed to the log file. However I do not understand how to import it into the files that main calls. How do I bring the file handler into processing_chain file? Currently from what I could understand from other places on stackoverflow, I just import logging and then use logging.info or any other level and it should follow. But it does not log to file, just to console.

Body:
Hey I am trying to set up a logger for python3.9 for an entire project, with multiple files. I want to just define the logger in main.py using command line arguments to define log file name.

logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level='INFO')
logger = logging.getLogger(__name__)

def main():

file_name = sys.argv[1]
lookback_minutes = int(sys.argv[2])
file_handler = logging.FileHandler(f'log/{file_name}.log')
logger.addHandler(file_handler)
logger.info(f'Running processing chain for: {file_name}')
processing_chain.run(lookback_minutes)

processing_chain file:

import logging

def run(lookback_minutes):
    logging.info(lookback_minutes)

Which works for main, I get the info statement printed to the log file. However I do not understand how to import it into the files that main calls. How do I bring the file handler into processing_chain file? Currently from what I could understand from other places on stackoverflow, I just import logging and then use logging.info or any other level and it should follow. But it does not log to file, just to console.


问:
Unable to access meta object in routes-VueJs
I am unable to access the neededPermissions array in the routes. I clearly have the array neededPermissions in routes but every time I try to access the array, console logs undefined.

How can I get the neededPermissions array from the meta object in routes? Clearly to.meta.neededPermissions prints undefined, which make's it impossible to loop through currentUser.

```<code>{
    path: "/administration",
    name: "Administration",
    component: PageAdministration,
    meta: {
      requiresAuth: true,
      neededPermissions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  },
}
</code>```

function to authorize users

```<code>  console.log(to.meta.neededPermissions );
if(currentUser!==null && to.meta.neededPermissions !== undefined)
  {
    for(let i = 0;i<currentUser.teams.length;i++){
      const team = currentUser.teams[i]
      const validPermissions = team.permissions.filter((item) => { return to.meta.neededPermissions.includes(item.permissionType); });
      const mappedValidPermissions = validPermissions.map((item) => { return item.permissionType;  });
      if (!to.meta.neededPermissions.every(i=>mappedValidPermissions.includes(i))) {
        isAllowed = false;
        next({ path: "/:notFound(.*)" });
        break;
      }
    } if(isAllowed) next();
}

</code>```

Body:
I am unable to access the neededPermissions array in the routes. I clearly have the array neededPermissions in routes but every time I try to access the array, console logs undefined.

How can I get the neededPermissions array from the meta object in routes? Clearly to.meta.neededPermissions prints undefined, which make's it impossible to loop through currentUser.

{
    path: "/administration",
    name: "Administration",
    component: PageAdministration,
    meta: {
      requiresAuth: true,
      neededPermissions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  },
}

function to authorize users

  console.log(to.meta.neededPermissions );
if(currentUser!==null && to.meta.neededPermissions !== undefined)
  {
    for(let i = 0;i<currentUser.teams.length;i++){
      const team = currentUser.teams[i]
      const validPermissions = team.permissions.filter((item) => { return to.meta.neededPermissions.includes(item.permissionType); });
      const mappedValidPermissions = validPermissions.map((item) => { return item.permissionType;  });
      if (!to.meta.neededPermissions.every(i=>mappedValidPermissions.includes(i))) {
        isAllowed = false;
        next({ path: "/:notFound(.*)" });
        break;
      }
    } if(isAllowed) next();
}


问:
Optimization of data-driven function as Tensorflow model
I try to find the optimum of a data-driven function represented as a Tensorflow model.

Means I trained a model to approximate a function and now want to find the optimum of this approximated function using a algorithm and software package/python library like ipopt, ipyopt, casadi, .... Or is there a possibility to do this directly in Tensorflow. I also have to define constraints, so I can't just use simple autodiff to do gradient decent and optimize my input.

Is there any idea how to realize this in an efficient way?

Maybe this image visualizes my problem to better understand what I'm looking for.


问:
PulseAudio switch on last used device
How do I make it so that when the device is disconnected, pulseaudio switches to the last used device, and not to the device that is first in the list?</p>

Title: PulseAudio switch on last used device


问:
How to use FocusEffect color in VCL Styles
FocusEffect is displayed as a color in the bitmap style designer however it is not defined in  TStyleColor.

I can see from the source that FocusEffect relates to TseStyleColor.ktcFocusEffect and should be able to fetch it with TSeStyle(FSource).Colors[ktcFocusEffect] however to do this requires getting the style source which is not accessible from the style and to make it more difficult  all of the Tse* definitions are in the implementation section of vcl.styles and therefore not accessible.

Due to this being a seemingly over complicated attack on the problem I presume I am going about it all wrong and there must be a way to access the custom style stuff without hacking around because if you were to create your own custom style with lots of newly defined colors etc. you would have to hack for each new entry.

I have a solution below but it seems excessive for what should be a trivial task.

unit StyleDirect;

interface

uses
  Winapi.Windows, Vcl.Graphics;

type
  TStyleDirect = class
  public
    class function FocusEffectColor: TColor;
  end;

implementation

uses
  System.Classes, System.SysUtils, Vcl.Direct2D, Winapi.D2D1, System.Types, Vcl.ImgList, Vcl.Consts, ZLib, StrUtils, Vcl.GraphUtil,
  Winapi.Messages, Vcl.Controls, Vcl.Styles, Vcl.Forms, Vcl.Themes;

{$I StyleUtils.inc}
{$I StyleAPI.inc}

type
  TStyleHelper = class helper for TCustomStyle
  public
    function GetSource: TObject;
  end;

function TStyleHelper.GetSource: TObject;
begin
  Result := Self.FSource;
end;

{ TStyleDirect }

class function TStyleDirect.FocusEffectColor: TColor;
begin
  if not TStyleManager.IsCustomStyleActive then
    Exit(GetSysColor(clHighlight));

  var Style := TCustomStyle(TStyleManager.ActiveStyle);
  var Source := Style.GetSource;

  Result:=TSeStyle(Source).Colors[ktcFocusEffect];
end;

end.```


问:
Creating new column in linux
This is my input file

chr     SNP     position        gene    effect_allele   other_allele    eaf     beta    se      pval    I2
1       rs143038218     11388792        UBIAD1  T       A       0.992   0.54    0.087   6.00E-10        0
1       rs945211        32191798        ADGRB2  G       C       0.383   -0.073  0.013   3.00E-08        0

I want to create a new column called CHR:POS_A1_A2 using 1st, 3rd, 5th and 6th columns respectively.

I'm using the following script:

```<code>awk -v OFS='\t' '{ if(NR==1) { print "chr\tSNP\tposition\tgene\teffect_allele\tother_allele\teaf\tbeta\tse\tpval\tI2\tCHR:POS_A1_A2" } else { print $0, $1":"$3"_"$5"_"$6 } }' IOP_2018_133_SNPs.txt > IOP_2018_133_SNPs_CPA1A2.txt
</code>```

My output is as follows:

==> IOP_2018_133_SNPs_CPA1A2.txt <==
chr     SNP     position        gene    effect_allele   other_allele    eaf     beta    se      pval    I2      CHR:POS_A1_A2
1       1:11388792_T_A  11388792        UBIAD1  T       A       0.992   0.54    0.087   6.00E-10        0
1       1:32191798_G_C  32191798        ADGRB2  G       C       0.383   -0.073  0.013   3.00E-08        0

For some reason the second column 'SNP' is missing in my output file. How can I address this issue TIA

Title: Creating new column in linux

Body:
This is my input file

chr     SNP     position        gene    effect_allele   other_allele    eaf     beta    se      pval    I2
1       rs143038218     11388792        UBIAD1  T       A       0.992   0.54    0.087   6.00E-10        0
1       rs945211        32191798        ADGRB2  G       C       0.383   -0.073  0.013   3.00E-08        0

I want to create a new column called CHR:POS_A1_A2 using 1st, 3rd, 5th and 6th columns respectively.

I'm using the following script:

awk -v OFS='\t' '{ if(NR==1) { print "chr\tSNP\tposition\tgene\teffect_allele\tother_allele\teaf\tbeta\tse\tpval\tI2\tCHR:POS_A1_A2" } else { print $0, $1":"$3"_"$5"_"$6 } }' IOP_2018_133_SNPs.txt > IOP_2018_133_SNPs_CPA1A2.txt

My output is as follows:

==> IOP_2018_133_SNPs_CPA1A2.txt <==
chr     SNP     position        gene    effect_allele   other_allele    eaf     beta    se      pval    I2      CHR:POS_A1_A2
1       1:11388792_T_A  11388792        UBIAD1  T       A       0.992   0.54    0.087   6.00E-10        0
1       1:32191798_G_C  32191798        ADGRB2  G       C       0.383   -0.073  0.013   3.00E-08        0

For some reason the second column 'SNP' is missing in my output file. How can I address this issue TIA


问:
Native browser tasks automation
I have some user tasks on the browser that I want to automate. These tasks involve page load/re-load. I am wondering if it is possible to write a javascript code using browser capabilities (like dev tool / local storage) to perform this.
Is it possible to write an extension to do that ?

My flow is the following :

Be on a page that has multiple listings of my own

Loop through each listing  to modify it.

Modifying each listing involves

clicking on a button "Modify", which brings user to https://xxxxxx/ modify.

Then do a bunch of clicks on that page (easy).

Then click on confirm which bring user to another page https://xxxxxx/ modify/confirmation.

Please note I am not looking for solutions that involve automation frameworks like Puppeteer or Selinium. I need to have javascript code or chrome extension.

Looking forward for your help

searched the web for two weeks no solutions

Title: Native browser tasks automation


问:
Eclipse: Issue with apt-maven-plugin generating an "empty" class
I have a project that uses the com.mysema.maven:apt-maven-plugin:1.0.4 to automatically generate classes used for query-DSL.

The project builds fine with maven executed on the command-line.

However, when I build the same project within Eclipse the "Q-classes" (so-called because they all have a name prefixed with 'Q') are generated except one of them:

Class QZHStRegisterJPBaseOptimisticLockingEntity is generated as "empty" file.

Oddly, that generated source file is not completely empty but it contains a package name and two imports but nothing more, i.e. it contains no class declaration and thus that class (which is referred to by many other classes) does not exists leading to tons of compile errors.

This is how the generated source file looks like:

```<code>package ch.zh.ksta.zhstregisterjp.dom.base;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.path.*;
</code>```

Does anyone have any idea why this is not working and what could cause the apt-maven-plugin to emit such a "half-baken" incomplete file???

Just in case: the plugin does get executed. I have defined a Maven lifecycle-mapping in eclipse like so:

```<code>                                ...
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.mysema.maven</groupId>
                                        <artifactId>apt-maven-plugin</artifactId> <!-- the new artifactId -->
                                        <versionRange>[1.0.4,)</versionRange>
                                        <goals>
                                            <goal>generate-sources</goal>
                                            <goal>process</goal>
                                            <goal>test-process</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <!-- ->
                                        <ignore/>
                                        <!- -->
                                        <execute>
                                            <runOnConfiguration>true</runOnConfiguration>
                                            <runOnIncremental>true</runOnIncremental>
                                        </execute>
                                    </action>
                                </pluginExecution>
                                ...
</code>```

Also, the Q-classes are generated fine during the build, except for that single "empty" one mentioned.

Body:
I have a project that uses the com.mysema.maven:apt-maven-plugin:1.0.4 to automatically generate classes used for query-DSL.

The project builds fine with maven executed on the command-line.

However, when I build the same project within Eclipse the "Q-classes" (so-called because they all have a name prefixed with 'Q') are generated except one of them:

Class QZHStRegisterJPBaseOptimisticLockingEntity is generated as "empty" file.

Oddly, that generated source file is not completely empty but it contains a package name and two imports but nothing more, i.e. it contains no class declaration and thus that class (which is referred to by many other classes) does not exists leading to tons of compile errors.

This is how the generated source file looks like:

package ch.zh.ksta.zhstregisterjp.dom.base;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.path.*;

Does anyone have any idea why this is not working and what could cause the apt-maven-plugin to emit such a "half-baken" incomplete file???

Just in case: the plugin does get executed. I have defined a Maven lifecycle-mapping in eclipse like so:

                                ...
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.mysema.maven</groupId>
                                        <artifactId>apt-maven-plugin</artifactId>
                                        <versionRange>[1.0.4,)</versionRange>
                                        <goals>
                                            <goal>generate-sources</goal>
                                            <goal>process</goal>
                                            <goal>test-process</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>

                                        <execute>
                                            <runOnConfiguration>true</runOnConfiguration>
                                            <runOnIncremental>true</runOnIncremental>
                                        </execute>
                                    </action>
                                </pluginExecution>
                                ...

Also, the Q-classes are generated fine during the build, except for that single "empty" one mentioned.


问:
Is it possible to send a message on dicord in case of exception in a loop?
I'm trying to send a message on exception in a loop on discord but I don't know if it's possible with postgres:

```<code>EXCEPTION WHEN OTHERS THEN
 GET STACKED DIAGNOSTICS text_var1 = MESSAGE_TEXT,
                          text_var2 = PG_EXCEPTION_DETAIL,
                          text_var3 = PG_EXCEPTION_HINT;
 raise notice '% % %', text_var1, text_var2, text_var3;

curl "https://discord.com/api/webhooks/TOKEN" \
  -H "Content-Type: application/json" \
    -d '{"username": "Toto", "content":":white_check_mark:  Exception"}'

end;
</code>```

My error:

```<code>NOTICE:  identifier "https://discord.com/api/webhooks/Toekn" will be truncated to "https://discord.com/api/webhooks/Token"

ERROR:  syntax error at or near "curl"
LINE 28: curl "https://discord.com/api/webhooks/...
         ^
État SQL : 42601
Caractère : 981
</code>```

Body:
I'm trying to send a message on exception in a loop on discord but I don't know if it's possible with postgres:

EXCEPTION WHEN OTHERS THEN
 GET STACKED DIAGNOSTICS text_var1 = MESSAGE_TEXT,
                          text_var2 = PG_EXCEPTION_DETAIL,
                          text_var3 = PG_EXCEPTION_HINT;
 raise notice '% % %', text_var1, text_var2, text_var3;

curl "https://discord.com/api/webhooks/TOKEN" \
  -H "Content-Type: application/json" \
    -d '{"username": "Toto", "content":":white_check_mark:  Exception"}'

end;

My error:

NOTICE:  identifier "https://discord.com/api/webhooks/Toekn" will be truncated to "https://discord.com/api/webhooks/Token"

ERROR:  syntax error at or near "curl"
LINE 28: curl "https://discord.com/api/webhooks/...
         ^
État SQL : 42601
Caractère : 981


问:
Using ReCharts in React with large data sets (~100,000 points)
I'd like to draw a line chart, using ReCharts in React, with a large data set (~100,000 points).

It takes a really long time (~30 seconds) for it to draw (for large data sets).

Is it possible to somehow optimize it and get a better performance?


问:
Filling gaps based on a trend from another column in Python data frame
I have one station with daily measurements of some feature. But there are several other places, where we measure the same feature about 10 to 14 times a year. Now I have to fill the gaps with values based on the trends of the reference station.

I've made a simplified version of data in the table below.

Problem 1: These values are not precisely related throughout the year: 100 on ref_station may match different values on another (e.g. 65 one day, 75 another time).

Problem 2: Between equal values on expeditionary measurements there can be slight changes on the reference station (6th to 9th jan.), so that can't be a simple linear interpolation between known values.

Date
ref_station
exped_1
exped_2

2022-01-01
100
65

2022-01-02
110

130

2022-01-03
115

2022-01-04
105

2022-01-05
110

2022-01-06
100
75

2022-01-07
105

2022-01-08
102

2022-01-09
100
75

2022-01-10
110

165

Below the same table filled with some values, that could be acceptable. I'm aware the method is not very reliable in the first place, but I just need a somewhat smoothed graph at the end.

Date
ref_station
exped_1
exped_2

2022-01-01
100
65

2022-01-02
110
73
130

2022-01-03
115
78
140

2022-01-04
105
76
136

2022-01-05
110
77
150

2022-01-06
100
75
143

2022-01-07
105
76
150

2022-01-08
102
75
149

2022-01-09
100
75
148

2022-01-10
110

165

I've only tried the standard Pandas interpolate function with different methods.
But I assume instead that I need to somehow move the 'box' between the known values and calculate some proportions in that box? Maybe I have calculate line by line? Or maybe there's some funcion which could be helpful for me?


问:
Word file keyword or text importing and save to excel sheet using python gui tkinter
I created a python gui using tkinter, the gui gui is showing but during i need to locate the Microsoft word files containing the .docx and .doc it can't see but empty folder. The importing and extraction will not proceed since it doesn't see the word files.
I install the modules,
as python script shown below. Any idea?

Analyze Python Program Requested

import docx

import openpyxl

import os

import tkinter as tk

import tkinter.ttk as ttk

from tkinter import filedialog

import threading

import win32com.client

Set the default directory and output location

default_directory = '/path/to/default/directory'

output_location = None

Create the GUI

root = tk.Tk()

root.geometry("300x250")

root.title('Data Extractor')

Create a label to display the current directory

label = tk.Label(root, text='Directory: ' + default_directory)

label.pack()

Create a button to select the directory

def select_directory():

```<code>global default_directory

directory = filedialog.askdirectory()

if directory:

    default_directory = directory

    label.config(text='Directory: ' + default_directory)
</code>```

button = tk.Button(root, text='Set Directory', command=select_directory)

button.pack()

Create a button to select the output location

def select_output_location():

```<code>global output_location

output_location = filedialog.asksaveasfilename(defaultextension='.xlsx', filetypes=[("Excel Workbook", "*.xlsx")])

if output_location:

   output_label.config(text='Output: ' + output_location)
</code>```

output_label = tk.Label(root, text='Output: ')

output_label.pack()

output_button = tk.Button(root, text='Set Output Location', command=select_output_location)

output_button.pack()

Create a progress bar

progress = ttk.Progressbar(root, length=200)

progress.pack()

Create a button to start the extraction

def extract_data():

```<code>if default_directory and output_location:

    thread = threading.Thread(target=extract_data_thread)

    thread.start()

else:

    tk.messagebox.showerror("Error", "Please select the directory, output location and check if it contain word files")
</code>```

def extract_data_thread():

```<code># Create a new Excel workbook

workbook = openpyxl.Workbook()

# Create a new sheet

sheet = workbook.create_sheet()

# Set the starting row for the data

row = 1

# Set the directory to the default or selected directory

directory = default_directory

# Get the number of files to process

file_count = 0

for root, dirs, files in os.walk(directory):

    file_count += len([f for f in files if f.endswith(('.docx', '.doc'))])

# Set the progress bar maximum value

progress['maximum'] = file_count

progress['value'] = 0

processed_files = 0

# Iterate over the files in the directory

for root, dirs, files in os.walk(directory):

    for filename in files:

        if filename.endswith(('.docx', '.doc')):

            try:

                if filename.endswith('.docx'):

                    doc = docx.Document(os.path.join(root, filename))

                    tables = doc.tables

                elif filename.endswith('.doc'):

                    word = win32com.client.Dispatch("Word.Application")

                    doc = word.Documents.Open(os.path.join(root, filename))

                    tables = doc.Tables

                else:

                    continue

                if tables:

                    table = tables[0]

                    model_no = table.cell(0,1).text

                    reference_number = table.cell(0,2).text

                    date_released = table.cell(1,1).text

                else:

                    continue

            except:

                print("An error occurred while processing file: " + filename)

                continue

            # Add the data to the sheet

            sheet.cell(row=row, column=1).value = filename

            sheet.cell(row=row, column=2).value = model_no

            sheet.cell(row=row, column=3).value = reference_number

            sheet.cell(row=row, column=4).value = date_released

            # Increment the row counter

            row += 1

                           # Update the progress bar

            processed_files += 1

            progress.set(processed_files)

            root.update()

if processed_files == 0:

    tk.messagebox.showerror("Error", "No word files or keyword detected")

else:

    # Save the workbook

    workbook.save(output_location)

    progress['value'] = 0

    print("Successfully saved data to: " + output_location)
</code>```

Create the "Extract Data" button

extract_button = tk.Button(root, text='Extract Data', command=extract_data)

extract_button.pack()

root.mainloop()

any idea how solve the issue?

Body:
I created a python gui using tkinter, the gui gui is showing but during i need to locate the Microsoft word files containing the .docx and .doc it can't see but empty folder. The importing and extraction will not proceed since it doesn't see the word files.
I install the modules,
as python script shown below. Any idea?

Analyze Python Program Requested

import docx

import openpyxl

import os

import tkinter as tk

import tkinter.ttk as ttk

from tkinter import filedialog

import threading

import win32com.client

Set the default directory and output location

default_directory = '/path/to/default/directory'

output_location = None

Create the GUI

root = tk.Tk()

root.geometry("300x250")

root.title('Data Extractor')

Create a label to display the current directory

label = tk.Label(root, text='Directory: ' + default_directory)

label.pack()

Create a button to select the directory

def select_directory():

global default_directory

directory = filedialog.askdirectory()

if directory:

    default_directory = directory

    label.config(text='Directory: ' + default_directory)

button = tk.Button(root, text='Set Directory', command=select_directory)

button.pack()

Create a button to select the output location

def select_output_location():

global output_location

output_location = filedialog.asksaveasfilename(defaultextension='.xlsx', filetypes=[("Excel Workbook", "*.xlsx")])

if output_location:

   output_label.config(text='Output: ' + output_location)

output_label = tk.Label(root, text='Output: ')

output_label.pack()

output_button = tk.Button(root, text='Set Output Location', command=select_output_location)

output_button.pack()

Create a progress bar

progress = ttk.Progressbar(root, length=200)

progress.pack()

Create a button to start the extraction

def extract_data():

if default_directory and output_location:

    thread = threading.Thread(target=extract_data_thread)

    thread.start()

else:

    tk.messagebox.showerror("Error", "Please select the directory, output location and check if it contain word files")

def extract_data_thread():

# Create a new Excel workbook

workbook = openpyxl.Workbook()

# Create a new sheet

sheet = workbook.create_sheet()

# Set the starting row for the data

row = 1

# Set the directory to the default or selected directory

directory = default_directory

# Get the number of files to process

file_count = 0

for root, dirs, files in os.walk(directory):

    file_count += len([f for f in files if f.endswith(('.docx', '.doc'))])

# Set the progress bar maximum value

progress['maximum'] = file_count

progress['value'] = 0

processed_files = 0

# Iterate over the files in the directory

for root, dirs, files in os.walk(directory):

    for filename in files:

        if filename.endswith(('.docx', '.doc')):

            try:

                if filename.endswith('.docx'):

                    doc = docx.Document(os.path.join(root, filename))

                    tables = doc.tables

                elif filename.endswith('.doc'):

                    word = win32com.client.Dispatch("Word.Application")

                    doc = word.Documents.Open(os.path.join(root, filename))

                    tables = doc.Tables

                else:

                    continue

                if tables:

                    table = tables[0]

                    model_no = table.cell(0,1).text

                    reference_number = table.cell(0,2).text

                    date_released = table.cell(1,1).text

                else:

                    continue

            except:

                print("An error occurred while processing file: " + filename)

                continue

            # Add the data to the sheet

            sheet.cell(row=row, column=1).value = filename

            sheet.cell(row=row, column=2).value = model_no

            sheet.cell(row=row, column=3).value = reference_number

            sheet.cell(row=row, column=4).value = date_released

            # Increment the row counter

            row += 1

                           # Update the progress bar

            processed_files += 1

            progress.set(processed_files)

            root.update()

if processed_files == 0:

    tk.messagebox.showerror("Error", "No word files or keyword detected")

else:

    # Save the workbook

    workbook.save(output_location)

    progress['value'] = 0

    print("Successfully saved data to: " + output_location)

Create the "Extract Data" button

extract_button = tk.Button(root, text='Extract Data', command=extract_data)

extract_button.pack()

root.mainloop()

any idea how solve the issue?