mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-07-01 20:26:27 +00:00
Compare commits
80 Commits
3b6134f063
...
0.3.0-refa
Author | SHA1 | Date | |
---|---|---|---|
2b8b13ca95
|
|||
743bbe209f
|
|||
a680a6fd7d
|
|||
ebb649aef6
|
|||
9d7054d29a
|
|||
4ea49ebeda
|
|||
113e022967
|
|||
0fd7d3aa5e
|
|||
8e9c61829d
|
|||
d143632025
|
|||
6e8ac3dee7
|
|||
779fe0130e
|
|||
5ca9a5aaa3
|
|||
2377d233b1
|
|||
3b9609ee82
|
|||
e93904bb0d
|
|||
f19ac4d8d5
|
|||
96551c61ca
|
|||
d270636862
|
|||
f10c3648a7
|
|||
6fb24d4907
|
|||
eab2a3e520
|
|||
caced6eaec
|
|||
990efee900
|
|||
10c869846c
|
|||
d97ed91631
|
|||
5e996d35d2
|
|||
bfa1472b5c
|
|||
bb163ad78d
|
|||
864f524e68
|
|||
03696650ea
|
|||
4e799034d7
|
|||
b8136bf25f
|
|||
86d7a86700
|
|||
a32453b989
|
|||
d52d234adc
|
|||
88201e2ca4
|
|||
43be27bd4a
|
|||
1c114816c0
|
|||
f6e5f45579
|
|||
a27afca8a7
|
|||
ce715bfccc
|
|||
0d5e21a90e
|
|||
a6d71135fb
|
|||
5f2b66233b
|
|||
e295e58388
|
|||
61d9916cae
|
|||
264b340dfa
|
|||
f359322b6c
|
|||
c705fea473
|
|||
c585e5ec04
|
|||
09fbebf7a4
|
|||
bb39a5912b
|
|||
b78040a795
|
|||
2204338a5e
|
|||
55e76ef650
|
|||
64285c350c
|
|||
62c3431cff
|
|||
280543660a
|
|||
8dc433b12a
|
|||
2bd64bbd5e
|
|||
54749c8df2
|
|||
36364d6e3d
|
|||
b14c3e82b4
|
|||
14f4cef426
|
|||
92fcc53015
|
|||
0764308638
|
|||
e5c1e0ef4a
|
|||
8c48d76c65
|
|||
d79c73df8c
|
|||
7a64ec4a4a
|
|||
a9f8ba6e22
|
|||
13ea4d9e97
|
|||
24d46e4615
|
|||
62c85e9e82
|
|||
c7de60ee03
|
|||
7c000d01cb
|
|||
5190d614c2
|
|||
a4daa9899a
|
|||
179d5783cb
|
48
.github/workflows/build-and-draft-release.yml
vendored
Normal file
48
.github/workflows/build-and-draft-release.yml
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
name: "Build and draft a release"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- "v[0-9]+.[0-9]+.[0-9]+"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
discussions: write
|
||||
|
||||
jobs:
|
||||
build-and-draft-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python environment
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
- name: Build package
|
||||
run: |
|
||||
pip install build
|
||||
python -m build
|
||||
|
||||
- name: Remove `v` in tag name
|
||||
uses: mad9000/actions-find-and-replace-string@5
|
||||
id: tagNameReplaced
|
||||
with:
|
||||
source: ${{ github.ref_name }}
|
||||
find: "v"
|
||||
replace: ""
|
||||
|
||||
- name: Draft a release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
discussion_category_name: New releases
|
||||
draft: true
|
||||
generate_release_notes: true
|
||||
files: |
|
||||
dist/arcaea_offline-${{ steps.tagNameReplaced.outputs.value }}*.whl
|
||||
dist/arcaea-offline-${{ steps.tagNameReplaced.outputs.value }}.tar.gz
|
54
.github/workflows/main.yml
vendored
Normal file
54
.github/workflows/main.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
name: test & lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
pull_request:
|
||||
types: [opened, reopened]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
pytest:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install dev dependencies
|
||||
run: "pip install .[dev]"
|
||||
- name: Run tests
|
||||
run: "python -m pytest -v"
|
||||
|
||||
ruff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install dev dependencies
|
||||
run: "pip install .[dev]"
|
||||
- name: Run linter
|
||||
run: "ruff check"
|
||||
|
||||
pyright:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install dev dependencies
|
||||
run: "pip install .[dev]"
|
||||
- name: Run pyright
|
||||
uses: jakebailey/pyright-action@v2
|
@ -4,11 +4,10 @@ repos:
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.1.0
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.11.12
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
- id: ruff
|
||||
args: ["--fix"]
|
||||
- id: ruff-format
|
||||
|
2
.sourcery.yaml
Normal file
2
.sourcery.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
rule_settings:
|
||||
python_version: '3.8'
|
675
LICENSE
675
LICENSE
@ -1,7 +1,674 @@
|
||||
Copyright 2023-now Lin He
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
Preamble
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
33
README.md
33
README.md
@ -1,22 +1,39 @@
|
||||
# Arcaea Offline
|
||||
|
||||
> 接受 <i><b>lr</b><sub>lowiro</sub></i> 的一切
|
||||
English | [简体中文](./README.zh_Hans.md)
|
||||
|
||||

|
||||
<span>
|
||||
<img src="./assets/banner.png" style="height: 175px; object-fit: contain;">
|
||||
</span>
|
||||
|
||||
> Accept <i><b>lr</b><sub>lowiro</sub></i>
|
||||
|
||||
## WIP
|
||||
|
||||
This project is under active development, thus it is unstable and API may change frequently.
|
||||
> **Warning**
|
||||
> This project is under active development, thus it is unstable and API may change frequently.
|
||||
|
||||
## 这事什么?
|
||||
## What is this?
|
||||
|
||||
这是用于计算 [Arcaea](https://arcaea.lowiro.com/) 中,玩家潜力值的 [B30 和 R10](https://wiki.arcaea.cn/潜力值#整体潜力值计算) 部分的程序。
|
||||
This is the core library of `Arcaea Offline`, designed to manage player scores, calculate their potential, and provide various useful tools.
|
||||
|
||||
## 这怎么用?
|
||||
## How to use this?
|
||||
|
||||
这个存储库是相对基础的,提供操作数据库等“底层”操作的 python 库。要使用该库,请查阅 API 手册(还没写)。
|
||||
This repository is a python library.
|
||||
|
||||
如果您正寻找 GUI,请前往 [283375/arcaea-offline-pyside-ui](https://github.com/283375/arcaea-offline-pyside-ui) 了解详情。
|
||||
For general users, if you don't know what is a "library", you may be interested about [this GUI](https://github.com/283375/arcaea-offline-pyside-ui).
|
||||
|
||||
For developers, the documentation is under construction. Check back later!
|
||||
|
||||
## License
|
||||
|
||||
This file is part of arcaea-offline.
|
||||
|
||||
arcaea-offline is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
arcaea-offline is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with arcaea-offline. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
## Credits
|
||||
|
||||
|
38
README.zh_Hans.md
Normal file
38
README.zh_Hans.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Arcaea Offline
|
||||
|
||||
<span>
|
||||
<img src="./assets/banner.png" style="height: 175px; object-fit: contain;">
|
||||
</span>
|
||||
|
||||
> 接受 <i><b>lr</b><sub>lowiro</sub></i> 的一切
|
||||
|
||||
## WIP
|
||||
|
||||
> **Warning**
|
||||
> 该项目正处于早期开发阶段,不能保证稳定性,且 API 可能随时变动。
|
||||
|
||||
## 这是什么?
|
||||
|
||||
这是 `Arcaea Offline` 的核心依赖库,用于维护分数数据库、计算潜力值,并提供一些实用工具。
|
||||
|
||||
## 这怎么用?
|
||||
|
||||
该仓库是一个 python 库。
|
||||
|
||||
对普通用户,如果你不知道“库”是什么,你应该对[这个 GUI](https://github.com/283375/arcaea-offline-pyside-ui) 更感兴趣。
|
||||
|
||||
对开发者,文档仍在建设当中,敬请期待。
|
||||
|
||||
## 许可声明
|
||||
|
||||
本文件是 arcaea-offline 的一部分。
|
||||
|
||||
arcaea-offline 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。
|
||||
|
||||
发布 arcaea-offline 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。
|
||||
|
||||
你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看 <https://www.gnu.org/licenses/>。
|
||||
|
||||
## Credits
|
||||
|
||||
[Arcaea-Infinity/ArcaeaSongDatabase](https://github.com/Arcaea-Infinity/ArcaeaSongDatabase)
|
BIN
assets/banner.png
Normal file
BIN
assets/banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 524 KiB |
Binary file not shown.
Before Width: | Height: | Size: 338 KiB |
84
assets/logo.svg
Normal file
84
assets/logo.svg
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="500"
|
||||
height="500"
|
||||
viewBox="0 0 500 500"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1">
|
||||
<linearGradient
|
||||
id="linearGradient1">
|
||||
<stop
|
||||
style="stop-color:#b9b6d8;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop1" />
|
||||
<stop
|
||||
style="stop-color:#b9b6d8;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop4" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient2">
|
||||
<stop
|
||||
style="stop-color:#413d5c;stop-opacity:1;"
|
||||
offset="0.1"
|
||||
id="stop2" />
|
||||
<stop
|
||||
style="stop-color:#34333e;stop-opacity:1;"
|
||||
offset="0.89999998"
|
||||
id="stop3" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
xlink:href="#linearGradient2"
|
||||
id="linearGradient3"
|
||||
x1="87.5"
|
||||
y1="165.07216"
|
||||
x2="418.75003"
|
||||
y2="359.92786"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
xlink:href="#linearGradient1"
|
||||
id="linearGradient6"
|
||||
x1="250"
|
||||
y1="55.144306"
|
||||
x2="250"
|
||||
y2="446.85571"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
</defs>
|
||||
<g
|
||||
id="layer1">
|
||||
<path
|
||||
style="display:inline;fill:url(#linearGradient3);fill-opacity:1;stroke:none;stroke-width:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 25,275 150,55.144305 H 350 L 475,275 362.50004,444.8557 H 137.49996 Z"
|
||||
id="path16" />
|
||||
<path
|
||||
style="display:inline;fill:#626080;fill-opacity:1;stroke:none;stroke-width:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 150,55.144305 110.28321,125 H 389.71679 L 350,55.144305 Z"
|
||||
id="path7" />
|
||||
<path
|
||||
style="display:inline;fill:none;fill-opacity:1;stroke:url(#linearGradient6);stroke-width:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 25,275 150,55.144305 H 350 L 475,275 362.50004,444.8557 H 137.49996 Z"
|
||||
id="path9" />
|
||||
<path
|
||||
style="font-size:50px;font-family:GeosansLight;-inkscape-font-specification:GeosansLight;letter-spacing:-1px;fill:#dcdaf2;stroke-width:20"
|
||||
d="m 174.4,81.347151 q 0,-4.05 -2.8,-6.45 -2.8,-2.4 -6.9,-2.4 H 156 v 35.699999 h 2 V 90.347151 h 6.7 q 4.1,0 6.9,-2.5 2.8,-2.4 2.8,-6.5 z m -2.05,0 q 0,3.25 -2.2,5.15 -2.2,1.8 -5.5,1.8 H 158 v -13.75 h 6.65 q 3.35,0 5.4,1.7 2.3,1.85 2.3,5.1 z m 41.19999,9 q 0,-8.1 -5.15,-13.25 -5.2,-5.1 -13.25,-5.1 -8.1,0 -13.25,5.15 -5.1,5.1 -5.1,13.2 0,8.1 5.15,13.249999 5.1,5.1 13.2,5.1 8.1,0 13.25,-5.15 5.15,-5.099999 5.15,-13.199999 z m -2.05,0 q 0,7.25 -4.55,11.799999 -4.6,4.5 -11.8,4.5 -7.15,0 -11.75,-4.6 -4.55,-4.549999 -4.55,-11.699999 0,-7.15 4.6,-11.75 4.6,-4.6 11.7,-4.6 7.2,0 11.8,4.6 4.55,4.55 4.55,11.75 z m 17.10003,-15.8 v -2.05 h -17.85 v 2.05 h 7.9 v 33.649999 h 2.05 V 74.547151 Z m 19.09996,33.649999 v -2.05 h -15.1 V 89.747151 h 15.1 v -2.2 h -15.1 v -13 h 15.1 v -2.05 h -17.15 v 35.699999 z m 31.94995,0.6 V 72.497151 h -2.05 v 30.999999 l -26.65,-31.249999 v 35.949999 h 2 V 77.897151 Z m 19.80005,-34.249999 v -2.05 h -17.85 v 2.05 h 7.9 v 33.649999 h 2.05 V 74.547151 Z M 303.4,108.19715 V 72.497151 h -2 v 35.699999 z m 32.84999,0 -14.3,-36.849999 -14.25,36.849999 h 2 l 4.15,-10.699999 h 16.25 l 4.1,10.699999 z m -7,-12.749999 h -14.6 l 7.3,-18.9 z m 21.09999,12.749999 v -2.05 h -10.05 V 72.497151 h -2 v 35.699999 z"
|
||||
id="text23"
|
||||
aria-label="POTENTIAL" />
|
||||
<path
|
||||
id="path3"
|
||||
style="display:inline;fill:#c6c3e5;stroke-width:4"
|
||||
d="m 250,170 c -32.54103,0.0757 -61.79382,19.85476 -73.98633,50.02539 -0.3378,-0.0116 -0.67571,-0.02 -1.01367,-0.0254 -30.3756,0 -55,24.6244 -55,55 0,30.3756 24.6244,55 55,55 h 75 39.08594 C 268.71234,317.72216 255,295.37888 255,270 255,235.53617 280.28555,206.6766 313.20703,201.02148 298.19408,181.63471 274.93594,170.00868 250,170 Z m 111.87305,84.33984 -52.53321,52.53321 C 314.13799,308.88757 319.42648,310 325,310 c 22.269,0 40,-17.731 40,-40 0,-5.57352 -1.11243,-10.86201 -3.12695,-15.66016 z"
|
||||
transform="translate(-2.5,20)" />
|
||||
<path
|
||||
id="circle14"
|
||||
style="color:#000000;fill:#dcdaf2;-inkscape-stroke:none"
|
||||
d="M 325 210 C 291.9222 210 265 236.9222 265 270 C 265 303.0778 291.9222 330 325 330 C 358.0778 330 385 303.0778 385 270 C 385 236.9222 358.0778 210 325 210 z M 325 220 C 337.03042 220 348.04772 224.22367 356.66211 231.26758 L 286.26758 301.66211 C 279.22367 293.04772 275 282.03042 275 270 C 275 242.3266 297.3266 220 325 220 z M 363.73242 238.33789 C 370.77633 246.95228 375 257.96958 375 270 C 375 297.6734 352.6734 320 325 320 C 312.96958 320 301.95228 315.77633 293.33789 308.73242 L 363.73242 238.33789 z "
|
||||
transform="translate(-2.5,20)" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.8 KiB |
@ -4,29 +4,50 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "arcaea-offline"
|
||||
version = "0.1.0"
|
||||
version = "0.3.0a0.dev0"
|
||||
authors = [{ name = "283375", email = "log_283375@163.com" }]
|
||||
description = "Manage your local Arcaea score database."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = [
|
||||
"beautifulsoup4==4.12.2",
|
||||
"SQLAlchemy==2.0.20",
|
||||
"SQLAlchemy-Utils==0.41.1",
|
||||
"Whoosh==2.7.4",
|
||||
]
|
||||
dependencies = ["SQLAlchemy==2.0.20", "SQLAlchemy-Utils==0.41.1"]
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["ruff~=0.6.8", "pre-commit~=3.3", "pytest~=7.4", "tox~=4.11"]
|
||||
|
||||
[project.urls]
|
||||
"Homepage" = "https://github.com/283375/arcaea-offline"
|
||||
"Bug Tracker" = "https://github.com/283375/arcaea-offline/issues"
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
src_paths = ["src/arcaea_offline"]
|
||||
|
||||
[tool.pyright]
|
||||
ignore = ["**/__debug*.*"]
|
||||
ignore = ["build/"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
# Full list: https://docs.astral.sh/ruff/rules
|
||||
select = [
|
||||
"E", # pycodestyle (Error)
|
||||
"W", # pycodestyle (Warning)
|
||||
"F", # pyflakes
|
||||
"I", # isort
|
||||
"PL", # pylint
|
||||
"N", # pep8-naming
|
||||
"FBT", # flake8-boolean-trap
|
||||
"A", # flake8-builtins
|
||||
"DTZ", # flake8-datetimez
|
||||
"LOG", # flake8-logging
|
||||
"Q", # flake8-quotes
|
||||
"G", # flake8-logging-format
|
||||
"PIE", # flake8-pie
|
||||
"PT", # flake8-pytest-style
|
||||
]
|
||||
ignore = [
|
||||
"E501", # line-too-long
|
||||
]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"tests/*" = [
|
||||
"PLR2004", # magic-value-comparison
|
||||
]
|
||||
|
@ -1,3 +1,4 @@
|
||||
black==23.3.0
|
||||
isort==5.12.0
|
||||
pre-commit==3.3.1
|
||||
ruff~=0.6.8
|
||||
pre-commit~=3.3
|
||||
pytest~=7.4
|
||||
tox~=4.11
|
||||
|
@ -1,4 +1,2 @@
|
||||
beautifulsoup4==4.12.2
|
||||
SQLAlchemy==2.0.20
|
||||
SQLAlchemy-Utils==0.41.1
|
||||
Whoosh==2.7.4
|
||||
|
@ -0,0 +1 @@
|
||||
DATABASE_VERSION = 5
|
||||
|
@ -1,8 +0,0 @@
|
||||
from .b30 import calculate_b30, get_b30_calculated_list
|
||||
from .score import (
|
||||
calculate_constants_from_play_rating,
|
||||
calculate_play_rating,
|
||||
calculate_score_modifier,
|
||||
calculate_score_range,
|
||||
calculate_shiny_pure,
|
||||
)
|
@ -1,24 +0,0 @@
|
||||
from decimal import Decimal
|
||||
from typing import Dict, List
|
||||
|
||||
from ..models.scores import ScoreCalculated
|
||||
|
||||
|
||||
def get_b30_calculated_list(
|
||||
calculated_list: List[ScoreCalculated],
|
||||
) -> List[ScoreCalculated]:
|
||||
best_scores: Dict[str, ScoreCalculated] = {}
|
||||
for calculated in calculated_list:
|
||||
key = f"{calculated.song_id}_{calculated.rating_class}"
|
||||
stored = best_scores.get(key)
|
||||
if stored and stored.score < calculated.score or not stored:
|
||||
best_scores[key] = calculated
|
||||
ret_list = list(best_scores.values())
|
||||
ret_list = sorted(ret_list, key=lambda c: c.potential, reverse=True)[:30]
|
||||
return ret_list
|
||||
|
||||
|
||||
def calculate_b30(calculated_list: List[ScoreCalculated]) -> Decimal:
|
||||
ptt_list = [Decimal(c.potential) for c in get_b30_calculated_list(calculated_list)]
|
||||
sum_ptt_list = sum(ptt_list)
|
||||
return (sum_ptt_list / len(ptt_list)) if sum_ptt_list else Decimal("0.0")
|
@ -1,64 +0,0 @@
|
||||
from dataclasses import dataclass
|
||||
from decimal import Decimal
|
||||
from math import floor
|
||||
from typing import Tuple, Union
|
||||
|
||||
|
||||
def calculate_score_range(notes: int, pure: int, far: int):
|
||||
single_note_score = 10000000 / Decimal(notes)
|
||||
|
||||
actual_score = floor(
|
||||
single_note_score * pure + single_note_score * Decimal(0.5) * far
|
||||
)
|
||||
return (actual_score, actual_score + pure)
|
||||
|
||||
|
||||
def calculate_score_modifier(score: int) -> Decimal:
|
||||
if score >= 10000000:
|
||||
return Decimal(2)
|
||||
elif score >= 9800000:
|
||||
return Decimal(1) + (Decimal(score - 9800000) / 200000)
|
||||
else:
|
||||
return Decimal(score - 9500000) / 300000
|
||||
|
||||
|
||||
def calculate_play_rating(constant: int, score: int) -> Decimal:
|
||||
score_modifier = calculate_score_modifier(score)
|
||||
return max(Decimal(0), Decimal(constant) / 10 + score_modifier)
|
||||
|
||||
|
||||
def calculate_shiny_pure(notes: int, score: int, pure: int, far: int) -> int:
|
||||
single_note_score = 10000000 / Decimal(notes)
|
||||
actual_score = single_note_score * pure + single_note_score * Decimal(0.5) * far
|
||||
return score - floor(actual_score)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConstantsFromPlayRatingResult:
|
||||
EXPlus: Tuple[Decimal, Decimal]
|
||||
EX: Tuple[Decimal, Decimal]
|
||||
AA: Tuple[Decimal, Decimal]
|
||||
A: Tuple[Decimal, Decimal]
|
||||
B: Tuple[Decimal, Decimal]
|
||||
C: Tuple[Decimal, Decimal]
|
||||
|
||||
|
||||
def calculate_constants_from_play_rating(play_rating: Union[Decimal, str, float, int]):
|
||||
play_rating = Decimal(play_rating)
|
||||
|
||||
ranges = []
|
||||
for upperScore, lowerScore in [
|
||||
(10000000, 9900000),
|
||||
(9899999, 9800000),
|
||||
(9799999, 9500000),
|
||||
(9499999, 9200000),
|
||||
(9199999, 8900000),
|
||||
(8899999, 8600000),
|
||||
]:
|
||||
upperScoreModifier = calculate_score_modifier(upperScore)
|
||||
lowerScoreModifier = calculate_score_modifier(lowerScore)
|
||||
ranges.append(
|
||||
(play_rating - upperScoreModifier, play_rating - lowerScoreModifier)
|
||||
)
|
||||
|
||||
return ConstantsFromPlayRatingResult(*ranges)
|
@ -1,175 +0,0 @@
|
||||
from decimal import Decimal
|
||||
from typing import Literal, Optional, Union
|
||||
|
||||
|
||||
class PlayResult:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
play_rating: Union[Decimal, str, float, int],
|
||||
partner_step: Union[Decimal, str, float, int],
|
||||
):
|
||||
self.__play_rating = play_rating
|
||||
self.__partner_step = partner_step
|
||||
|
||||
@property
|
||||
def play_rating(self):
|
||||
return Decimal(self.__play_rating)
|
||||
|
||||
@property
|
||||
def partner_step(self):
|
||||
return Decimal(self.__partner_step)
|
||||
|
||||
|
||||
class PartnerBonus:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
step_bonus: Union[Decimal, str, float, int] = Decimal("0.0"),
|
||||
final_multiplier: Union[Decimal, str, float, int] = Decimal("1.0"),
|
||||
):
|
||||
self.__step_bonus = step_bonus
|
||||
self.__final_multiplier = final_multiplier
|
||||
|
||||
@property
|
||||
def step_bonus(self):
|
||||
return Decimal(self.__step_bonus)
|
||||
|
||||
@property
|
||||
def final_multiplier(self):
|
||||
return Decimal(self.__final_multiplier)
|
||||
|
||||
|
||||
AwakenedIlithPartnerBonus = PartnerBonus(step_bonus="6.0")
|
||||
AwakenedEtoPartnerBonus = PartnerBonus(step_bonus="7.0")
|
||||
AwakenedLunaPartnerBonus = PartnerBonus(step_bonus="7.0")
|
||||
|
||||
|
||||
class AwakenedAyuPartnerBonus(PartnerBonus):
|
||||
def __init__(self, step_bonus: Union[Decimal, str, float, int]):
|
||||
super().__init__(step_bonus=step_bonus)
|
||||
|
||||
|
||||
AmaneBelowExPartnerBonus = PartnerBonus(final_multiplier="0.5")
|
||||
|
||||
|
||||
class MithraTerceraPartnerBonus(PartnerBonus):
|
||||
def __init__(self, step_bonus: int):
|
||||
super().__init__(step_bonus=step_bonus)
|
||||
|
||||
|
||||
MayaPartnerBonus = PartnerBonus(final_multiplier="2.0")
|
||||
|
||||
|
||||
class StepBooster:
|
||||
def final_value(self) -> Decimal:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class LegacyMapStepBooster(StepBooster):
|
||||
def __init__(
|
||||
self,
|
||||
stamina: Literal[2, 4, 6],
|
||||
fragments: Literal[100, 250, 500, None],
|
||||
):
|
||||
self.stamina = stamina
|
||||
self.fragments = fragments
|
||||
|
||||
@property
|
||||
def stamina(self):
|
||||
return self.__stamina
|
||||
|
||||
@stamina.setter
|
||||
def stamina(self, value: Literal[2, 4, 6]):
|
||||
if value not in [2, 4, 6]:
|
||||
raise ValueError("stamina can only be one of [2, 4, 6]")
|
||||
self.__stamina = value
|
||||
|
||||
@property
|
||||
def fragments(self):
|
||||
return self.__fragments
|
||||
|
||||
@fragments.setter
|
||||
def fragments(self, value: Literal[100, 250, 500, None]):
|
||||
if value not in [100, 250, 500, None]:
|
||||
raise ValueError("fragments can only be one of [100, 250, 500, None]")
|
||||
self.__fragments = value
|
||||
|
||||
def final_value(self) -> Decimal:
|
||||
stamina_multiplier = Decimal(self.stamina)
|
||||
if self.fragments is None:
|
||||
fragments_multiplier = Decimal(1)
|
||||
elif self.fragments == 100:
|
||||
fragments_multiplier = Decimal("1.1")
|
||||
elif self.fragments == 250:
|
||||
fragments_multiplier = Decimal("1.25")
|
||||
elif self.fragments == 500:
|
||||
fragments_multiplier = Decimal("1.5")
|
||||
return stamina_multiplier * fragments_multiplier
|
||||
|
||||
|
||||
class MemoriesStepBooster(StepBooster):
|
||||
def final_value(self) -> Decimal:
|
||||
return Decimal("4.0")
|
||||
|
||||
|
||||
def calculate_step_original(
|
||||
play_result: PlayResult,
|
||||
*,
|
||||
partner_bonus: Optional[PartnerBonus] = None,
|
||||
step_booster: Optional[StepBooster] = None,
|
||||
):
|
||||
ptt = play_result.play_rating
|
||||
step = play_result.partner_step
|
||||
if partner_bonus:
|
||||
partner_bonus_step = partner_bonus.step_bonus
|
||||
partner_bonus_multiplier = partner_bonus.final_multiplier
|
||||
else:
|
||||
partner_bonus_step = Decimal("0")
|
||||
partner_bonus_multiplier = Decimal("1.0")
|
||||
|
||||
play_result = (Decimal("2.45") * ptt.sqrt() + Decimal("2.5")) * (step / 50)
|
||||
play_result += partner_bonus_step
|
||||
play_result *= partner_bonus_multiplier
|
||||
if step_booster:
|
||||
play_result *= step_booster.final_value()
|
||||
|
||||
return play_result
|
||||
|
||||
|
||||
def calculate_step(
|
||||
play_result: PlayResult,
|
||||
*,
|
||||
partner_bonus: Optional[PartnerBonus] = None,
|
||||
step_booster: Optional[StepBooster] = None,
|
||||
):
|
||||
play_result_original = calculate_step_original(
|
||||
play_result, partner_bonus=partner_bonus, step_booster=step_booster
|
||||
)
|
||||
|
||||
return round(play_result_original, 1)
|
||||
|
||||
|
||||
def calculate_play_rating_from_step(
|
||||
step: Union[Decimal, str, int, float],
|
||||
partner_step_value: Union[Decimal, str, int, float],
|
||||
*,
|
||||
partner_bonus: Optional[PartnerBonus] = None,
|
||||
step_booster: Optional[StepBooster] = None,
|
||||
):
|
||||
step = Decimal(step)
|
||||
partner_step_value = Decimal(partner_step_value)
|
||||
|
||||
# get original play result
|
||||
if partner_bonus and partner_bonus.final_multiplier:
|
||||
step /= partner_bonus.final_multiplier
|
||||
if step_booster:
|
||||
step /= step_booster.final_value()
|
||||
|
||||
if partner_bonus and partner_bonus.step_bonus:
|
||||
step -= partner_bonus.step_bonus
|
||||
|
||||
play_rating_sqrt = (Decimal(50) * step - Decimal("2.5") * partner_step_value) / (
|
||||
Decimal("2.45") * partner_step_value
|
||||
)
|
||||
return play_rating_sqrt**2 if play_rating_sqrt >= 0 else -(play_rating_sqrt**2)
|
3
src/arcaea_offline/calculators/__init__.py
Normal file
3
src/arcaea_offline/calculators/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .play_result import PlayResultCalculators
|
||||
|
||||
__all__ = ["PlayResultCalculators"]
|
105
src/arcaea_offline/calculators/play_result.py
Normal file
105
src/arcaea_offline/calculators/play_result.py
Normal file
@ -0,0 +1,105 @@
|
||||
from decimal import Decimal
|
||||
from math import floor
|
||||
from typing import Tuple, TypedDict, Union
|
||||
|
||||
from arcaea_offline.constants.play_result import ScoreLowerLimits
|
||||
|
||||
|
||||
class PlayResultCalculators:
|
||||
@staticmethod
|
||||
def score_possible_range(notes: int, pure: int, far: int) -> Tuple[int, int]:
|
||||
"""
|
||||
Returns the possible range of score based on the given values.
|
||||
|
||||
The first integer of returned tuple is the lower limit of the score,
|
||||
and the second integer is the upper limit.
|
||||
|
||||
For example, ...
|
||||
"""
|
||||
single_note_score = 10000000 / Decimal(notes)
|
||||
|
||||
actual_score = floor(
|
||||
single_note_score * pure + single_note_score * Decimal(0.5) * far
|
||||
)
|
||||
return (actual_score, actual_score + pure)
|
||||
|
||||
@staticmethod
|
||||
def shiny_pure(notes: int, score: int, pure: int, far: int) -> int:
|
||||
single_note_score = 10000000 / Decimal(notes)
|
||||
actual_score = single_note_score * pure + single_note_score * Decimal(0.5) * far
|
||||
return score - floor(actual_score)
|
||||
|
||||
@staticmethod
|
||||
def score_modifier(score: int) -> Decimal:
|
||||
"""
|
||||
Returns the score modifier of the given score
|
||||
|
||||
https://arcaea.fandom.com/wiki/Potential#Score_Modifier
|
||||
|
||||
:param score: The score of the play result, e.g. 9900000
|
||||
:return: The modifier of the given score, e.g. Decimal("1.5")
|
||||
"""
|
||||
if not isinstance(score, int):
|
||||
raise TypeError("score must be an integer")
|
||||
if score < 0:
|
||||
raise ValueError("score cannot be negative")
|
||||
|
||||
if score >= ScoreLowerLimits.PM:
|
||||
return Decimal(2)
|
||||
if score >= ScoreLowerLimits.EX:
|
||||
return Decimal(1) + (Decimal(score - 9800000) / 200000)
|
||||
return Decimal(score - 9500000) / 300000
|
||||
|
||||
@classmethod
|
||||
def play_rating(cls, score: int, constant: int) -> Decimal:
|
||||
"""
|
||||
Returns the play rating of the given score
|
||||
|
||||
https://arcaea.fandom.com/wiki/Potential#Play_Rating
|
||||
|
||||
:param constant: The (constant * 10) of the played chart, e.g. 120 for Testify[BYD]
|
||||
:param score: The score of the play result, e.g. 10002221
|
||||
:return: The play rating of the given values, e.g. Decimal("14.0")
|
||||
"""
|
||||
if not isinstance(score, int):
|
||||
raise TypeError("score must be an integer")
|
||||
if not isinstance(constant, int):
|
||||
raise TypeError("constant must be an integer")
|
||||
if score < 0:
|
||||
raise ValueError("score cannot be negative")
|
||||
if constant < 0:
|
||||
raise ValueError("constant cannot be negative")
|
||||
|
||||
score_modifier = cls.score_modifier(score)
|
||||
return max(Decimal(0), Decimal(constant) / 10 + score_modifier)
|
||||
|
||||
class ConstantsFromPlayRatingResult(TypedDict):
|
||||
EX_PLUS: Tuple[Decimal, Decimal]
|
||||
EX: Tuple[Decimal, Decimal]
|
||||
AA: Tuple[Decimal, Decimal]
|
||||
A: Tuple[Decimal, Decimal]
|
||||
B: Tuple[Decimal, Decimal]
|
||||
C: Tuple[Decimal, Decimal]
|
||||
|
||||
@classmethod
|
||||
def constants_from_play_rating(
|
||||
cls, play_rating: Union[Decimal, str, float, int]
|
||||
) -> ConstantsFromPlayRatingResult:
|
||||
play_rating = Decimal(play_rating)
|
||||
|
||||
def _result(score_upper: int, score_lower: int) -> Tuple[Decimal, Decimal]:
|
||||
upper_score_modifier = cls.score_modifier(score_upper)
|
||||
lower_score_modifier = cls.score_modifier(score_lower)
|
||||
return (
|
||||
play_rating - upper_score_modifier,
|
||||
play_rating - lower_score_modifier,
|
||||
)
|
||||
|
||||
return {
|
||||
"EX_PLUS": _result(10000000, ScoreLowerLimits.EX_PLUS),
|
||||
"EX": _result(ScoreLowerLimits.EX_PLUS - 1, ScoreLowerLimits.EX),
|
||||
"AA": _result(ScoreLowerLimits.EX - 1, ScoreLowerLimits.AA),
|
||||
"A": _result(ScoreLowerLimits.AA - 1, ScoreLowerLimits.A),
|
||||
"B": _result(ScoreLowerLimits.A - 1, ScoreLowerLimits.B),
|
||||
"C": _result(ScoreLowerLimits.B - 1, ScoreLowerLimits.C),
|
||||
}
|
25
src/arcaea_offline/calculators/world/__init__.py
Normal file
25
src/arcaea_offline/calculators/world/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
from ._common import MemoriesStepBooster, PartnerBonus, WorldPlayResult
|
||||
from .legacy import LegacyMapStepBooster
|
||||
from .main import WorldMainMapCalculators
|
||||
from .partners import (
|
||||
AmaneBelowExPartnerBonus,
|
||||
AwakenedEtoPartnerBonus,
|
||||
AwakenedIlithPartnerBonus,
|
||||
AwakenedLunaPartnerBonus,
|
||||
MayaPartnerBonus,
|
||||
MithraTerceraPartnerBonus,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"AmaneBelowExPartnerBonus",
|
||||
"AwakenedEtoPartnerBonus",
|
||||
"AwakenedIlithPartnerBonus",
|
||||
"AwakenedLunaPartnerBonus",
|
||||
"LegacyMapStepBooster",
|
||||
"MayaPartnerBonus",
|
||||
"MemoriesStepBooster",
|
||||
"MithraTerceraPartnerBonus",
|
||||
"PartnerBonus",
|
||||
"WorldMainMapCalculators",
|
||||
"WorldPlayResult",
|
||||
]
|
50
src/arcaea_offline/calculators/world/_common.py
Normal file
50
src/arcaea_offline/calculators/world/_common.py
Normal file
@ -0,0 +1,50 @@
|
||||
from decimal import Decimal
|
||||
from typing import Union
|
||||
|
||||
|
||||
class WorldPlayResult:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
play_rating: Union[Decimal, str, float, int],
|
||||
partner_step: Union[Decimal, str, float, int],
|
||||
):
|
||||
self.__play_rating = play_rating
|
||||
self.__partner_step = partner_step
|
||||
|
||||
@property
|
||||
def play_rating(self):
|
||||
return Decimal(self.__play_rating)
|
||||
|
||||
@property
|
||||
def partner_step(self):
|
||||
return Decimal(self.__partner_step)
|
||||
|
||||
|
||||
class PartnerBonus:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
step_bonus: Union[Decimal, str, float, int] = Decimal("0.0"),
|
||||
final_multiplier: Union[Decimal, str, float, int] = Decimal("1.0"),
|
||||
):
|
||||
self.__step_bonus = step_bonus
|
||||
self.__final_multiplier = final_multiplier
|
||||
|
||||
@property
|
||||
def step_bonus(self):
|
||||
return Decimal(self.__step_bonus)
|
||||
|
||||
@property
|
||||
def final_multiplier(self):
|
||||
return Decimal(self.__final_multiplier)
|
||||
|
||||
|
||||
class StepBooster:
|
||||
def final_value(self) -> Decimal:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class MemoriesStepBooster(StepBooster):
|
||||
def final_value(self) -> Decimal:
|
||||
return Decimal("4.0")
|
46
src/arcaea_offline/calculators/world/legacy.py
Normal file
46
src/arcaea_offline/calculators/world/legacy.py
Normal file
@ -0,0 +1,46 @@
|
||||
from decimal import Decimal
|
||||
from typing import Literal
|
||||
|
||||
from ._common import StepBooster
|
||||
|
||||
|
||||
class LegacyMapStepBooster(StepBooster):
|
||||
__fragment_boost_multipliers = {
|
||||
None: Decimal("1.0"),
|
||||
100: Decimal("1.1"),
|
||||
250: Decimal("1.25"),
|
||||
500: Decimal("1.5"),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
stamina: Literal[2, 4, 6],
|
||||
fragments: Literal[100, 250, 500, None],
|
||||
):
|
||||
self.stamina = stamina
|
||||
self.fragments = fragments
|
||||
|
||||
@property
|
||||
def stamina(self):
|
||||
return self.__stamina
|
||||
|
||||
@stamina.setter
|
||||
def stamina(self, value: Literal[2, 4, 6]):
|
||||
if value not in [2, 4, 6]:
|
||||
raise ValueError("stamina can only be one of [2, 4, 6]")
|
||||
self.__stamina = value
|
||||
|
||||
@property
|
||||
def fragments(self):
|
||||
return self.__fragments
|
||||
|
||||
@fragments.setter
|
||||
def fragments(self, value: Literal[100, 250, 500, None]):
|
||||
if value not in [100, 250, 500, None]:
|
||||
raise ValueError("fragments can only be one of [100, 250, 500, None]")
|
||||
self.__fragments = value
|
||||
|
||||
def final_value(self) -> Decimal:
|
||||
stamina_multiplier = Decimal(self.stamina)
|
||||
fragments_multiplier = self.__fragment_boost_multipliers[self.fragments]
|
||||
return stamina_multiplier * fragments_multiplier
|
55
src/arcaea_offline/calculators/world/main.py
Normal file
55
src/arcaea_offline/calculators/world/main.py
Normal file
@ -0,0 +1,55 @@
|
||||
from decimal import Decimal
|
||||
from typing import Optional, Union
|
||||
|
||||
from ._common import PartnerBonus, StepBooster, WorldPlayResult
|
||||
|
||||
|
||||
class WorldMainMapCalculators:
|
||||
@staticmethod
|
||||
def step(
|
||||
play_result: WorldPlayResult,
|
||||
*,
|
||||
partner_bonus: Optional[PartnerBonus] = None,
|
||||
step_booster: Optional[StepBooster] = None,
|
||||
) -> Decimal:
|
||||
ptt = play_result.play_rating
|
||||
step = play_result.partner_step
|
||||
if partner_bonus:
|
||||
partner_bonus_step = partner_bonus.step_bonus
|
||||
partner_bonus_multiplier = partner_bonus.final_multiplier
|
||||
else:
|
||||
partner_bonus_step = Decimal("0")
|
||||
partner_bonus_multiplier = Decimal("1.0")
|
||||
|
||||
result = (Decimal("2.45") * ptt.sqrt() + Decimal("2.5")) * (step / 50)
|
||||
result += partner_bonus_step
|
||||
result *= partner_bonus_multiplier
|
||||
if step_booster:
|
||||
result *= step_booster.final_value()
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def play_rating_from_step(
|
||||
step: Union[Decimal, str, int, float],
|
||||
partner_step_value: Union[Decimal, str, int, float],
|
||||
*,
|
||||
partner_bonus: Optional[PartnerBonus] = None,
|
||||
step_booster: Optional[StepBooster] = None,
|
||||
):
|
||||
step = Decimal(step)
|
||||
partner_step_value = Decimal(partner_step_value)
|
||||
|
||||
# get original play result
|
||||
if partner_bonus and partner_bonus.final_multiplier:
|
||||
step /= partner_bonus.final_multiplier
|
||||
if step_booster:
|
||||
step /= step_booster.final_value()
|
||||
|
||||
if partner_bonus and partner_bonus.step_bonus:
|
||||
step -= partner_bonus.step_bonus
|
||||
|
||||
play_rating_sqrt = (
|
||||
Decimal(50) * step - Decimal("2.5") * partner_step_value
|
||||
) / (Decimal("2.45") * partner_step_value)
|
||||
return play_rating_sqrt**2 if play_rating_sqrt >= 0 else -(play_rating_sqrt**2)
|
16
src/arcaea_offline/calculators/world/partners.py
Normal file
16
src/arcaea_offline/calculators/world/partners.py
Normal file
@ -0,0 +1,16 @@
|
||||
from ._common import PartnerBonus
|
||||
|
||||
AwakenedIlithPartnerBonus = PartnerBonus(step_bonus="6.0")
|
||||
AwakenedEtoPartnerBonus = PartnerBonus(step_bonus="7.0")
|
||||
AwakenedLunaPartnerBonus = PartnerBonus(step_bonus="7.0")
|
||||
|
||||
|
||||
AmaneBelowExPartnerBonus = PartnerBonus(final_multiplier="0.5")
|
||||
|
||||
|
||||
class MithraTerceraPartnerBonus(PartnerBonus):
|
||||
def __init__(self, step_bonus: int):
|
||||
super().__init__(step_bonus=step_bonus)
|
||||
|
||||
|
||||
MayaPartnerBonus = PartnerBonus(final_multiplier="2.0")
|
0
src/arcaea_offline/constants/__init__.py
Normal file
0
src/arcaea_offline/constants/__init__.py
Normal file
15
src/arcaea_offline/constants/enums/__init__.py
Normal file
15
src/arcaea_offline/constants/enums/__init__.py
Normal file
@ -0,0 +1,15 @@
|
||||
from .arcaea import (
|
||||
ArcaeaLanguage,
|
||||
ArcaeaPlayResultClearType,
|
||||
ArcaeaPlayResultModifier,
|
||||
ArcaeaRatingClass,
|
||||
ArcaeaSongSide,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"ArcaeaLanguage",
|
||||
"ArcaeaPlayResultClearType",
|
||||
"ArcaeaPlayResultModifier",
|
||||
"ArcaeaRatingClass",
|
||||
"ArcaeaSongSide",
|
||||
]
|
39
src/arcaea_offline/constants/enums/arcaea.py
Normal file
39
src/arcaea_offline/constants/enums/arcaea.py
Normal file
@ -0,0 +1,39 @@
|
||||
from enum import Enum, IntEnum
|
||||
|
||||
|
||||
class ArcaeaRatingClass(IntEnum):
|
||||
PAST = 0
|
||||
PRESENT = 1
|
||||
FUTURE = 2
|
||||
BEYOND = 3
|
||||
ETERNAL = 4
|
||||
|
||||
|
||||
class ArcaeaSongSide(IntEnum):
|
||||
LIGHT = 0
|
||||
CONFLICT = 1
|
||||
COLORLESS = 2
|
||||
LEPHON = 3
|
||||
|
||||
|
||||
class ArcaeaPlayResultModifier(IntEnum):
|
||||
NORMAL = 0
|
||||
EASY = 1
|
||||
HARD = 2
|
||||
|
||||
|
||||
class ArcaeaPlayResultClearType(IntEnum):
|
||||
TRACK_LOST = 0
|
||||
NORMAL_CLEAR = 1
|
||||
FULL_RECALL = 2
|
||||
PURE_MEMORY = 3
|
||||
HARD_CLEAR = 4
|
||||
EASY_CLEAR = 5
|
||||
|
||||
|
||||
class ArcaeaLanguage(Enum):
|
||||
EN = "en"
|
||||
JA = "ja"
|
||||
KO = "ko"
|
||||
ZH_HANT = "zh-Hant"
|
||||
ZH_HANS = "zh-Hans"
|
13
src/arcaea_offline/constants/play_result.py
Normal file
13
src/arcaea_offline/constants/play_result.py
Normal file
@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ScoreLowerLimits:
|
||||
PM = 10000000
|
||||
EX_PLUS = 9900000
|
||||
EX = 9800000
|
||||
AA = 9500000
|
||||
A = 9200000
|
||||
B = 8900000
|
||||
C = 8600000
|
||||
D = 0
|
@ -1,397 +0,0 @@
|
||||
import logging
|
||||
import math
|
||||
from typing import Iterable, List, Optional, Type, Union
|
||||
|
||||
from sqlalchemy import Engine, func, inspect, select
|
||||
from sqlalchemy.orm import DeclarativeBase, InstrumentedAttribute, sessionmaker
|
||||
|
||||
from .calculate import calculate_score_modifier
|
||||
from .external.arcsong.arcsong_json import ArcSongJsonBuilder
|
||||
from .external.exports import ScoreExport, exporters
|
||||
from .models.config import *
|
||||
from .models.scores import *
|
||||
from .models.songs import *
|
||||
from .singleton import Singleton
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Database(metaclass=Singleton):
|
||||
def __init__(self, engine: Optional[Engine]):
|
||||
try:
|
||||
self.__engine
|
||||
except AttributeError:
|
||||
self.__engine = None
|
||||
|
||||
if engine is None:
|
||||
if isinstance(self.engine, Engine):
|
||||
return
|
||||
raise ValueError("No sqlalchemy.Engine instance specified before.")
|
||||
elif isinstance(engine, Engine):
|
||||
if isinstance(self.engine, Engine):
|
||||
logger.warning(
|
||||
f"A sqlalchemy.Engine instance {self.engine} has been specified "
|
||||
f"and will be replaced to {engine}"
|
||||
)
|
||||
self.engine = engine
|
||||
else:
|
||||
raise ValueError(
|
||||
f"A sqlalchemy.Engine instance expected, not {repr(engine)}"
|
||||
)
|
||||
|
||||
@property
|
||||
def engine(self) -> Engine:
|
||||
return self.__engine # type: ignore
|
||||
|
||||
@engine.setter
|
||||
def engine(self, value: Engine):
|
||||
if not isinstance(value, Engine):
|
||||
raise ValueError("Database.engine only accepts sqlalchemy.Engine")
|
||||
self.__engine = value
|
||||
self.__sessionmaker = sessionmaker(self.__engine)
|
||||
|
||||
@property
|
||||
def sessionmaker(self):
|
||||
return self.__sessionmaker
|
||||
|
||||
# region init
|
||||
|
||||
def init(self, checkfirst: bool = True):
|
||||
# create tables & views
|
||||
if checkfirst:
|
||||
# > https://github.com/kvesteri/sqlalchemy-utils/issues/396
|
||||
# > view.create_view() causes DuplicateTableError on Base.metadata.create_all(checkfirst=True)
|
||||
# so if `checkfirst` is True, drop these views before creating
|
||||
SongsViewBase.metadata.drop_all(self.engine)
|
||||
ScoresViewBase.metadata.drop_all(self.engine)
|
||||
|
||||
SongsBase.metadata.create_all(self.engine, checkfirst=checkfirst)
|
||||
SongsViewBase.metadata.create_all(self.engine)
|
||||
ScoresBase.metadata.create_all(self.engine, checkfirst=checkfirst)
|
||||
ScoresViewBase.metadata.create_all(self.engine)
|
||||
ConfigBase.metadata.create_all(self.engine, checkfirst=checkfirst)
|
||||
|
||||
# insert version property
|
||||
with self.sessionmaker() as session:
|
||||
stmt = select(Property.value).where(Property.key == "version")
|
||||
result = session.execute(stmt).fetchone()
|
||||
if not checkfirst or not result:
|
||||
session.add(Property(key="version", value="4"))
|
||||
session.commit()
|
||||
|
||||
def check_init(self) -> bool:
|
||||
# check table exists
|
||||
expect_tables = (
|
||||
list(SongsBase.metadata.tables.keys())
|
||||
+ list(ScoresBase.metadata.tables.keys())
|
||||
+ list(ConfigBase.metadata.tables.keys())
|
||||
+ [
|
||||
Chart.__tablename__,
|
||||
ScoreCalculated.__tablename__,
|
||||
ScoreBest.__tablename__,
|
||||
CalculatedPotential.__tablename__,
|
||||
]
|
||||
)
|
||||
return all(inspect(self.engine).has_table(t) for t in expect_tables)
|
||||
|
||||
# endregion
|
||||
|
||||
def version(self) -> Union[int, None]:
|
||||
stmt = select(Property).where(Property.key == "version")
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return None if result is None else int(result.value)
|
||||
|
||||
# region Pack
|
||||
|
||||
def get_packs(self):
|
||||
stmt = select(Pack)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_pack(self, pack_id: str):
|
||||
stmt = select(Pack).where(Pack.id == pack_id)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
def get_pack_localized(self, pack_id: str):
|
||||
stmt = select(PackLocalized).where(PackLocalized.id == pack_id)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# endregion
|
||||
|
||||
# region Song
|
||||
|
||||
def get_songs(self):
|
||||
stmt = select(Song)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_songs_by_pack_id(self, pack_id: str):
|
||||
stmt = select(Song).where(Song.set == pack_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_song(self, song_id: str):
|
||||
stmt = select(Song).where(Song.id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
def get_song_localized(self, song_id: str):
|
||||
stmt = select(SongLocalized).where(SongLocalized.id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# endregion
|
||||
|
||||
# region Difficulty
|
||||
|
||||
def get_difficulties(self):
|
||||
stmt = select(Difficulty)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_difficulties_by_song_id(self, song_id: str):
|
||||
stmt = select(Difficulty).where(Difficulty.song_id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_difficulties_localized_by_song_id(self, song_id: str):
|
||||
stmt = select(DifficultyLocalized).where(DifficultyLocalized.song_id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_difficulty(self, song_id: str, rating_class: int):
|
||||
stmt = select(Difficulty).where(
|
||||
(Difficulty.song_id == song_id) & (Difficulty.rating_class == rating_class)
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
def get_difficulty_localized(self, song_id: str, rating_class: int):
|
||||
stmt = select(DifficultyLocalized).where(
|
||||
(DifficultyLocalized.song_id == song_id)
|
||||
& (DifficultyLocalized.rating_class == rating_class)
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# endregion
|
||||
|
||||
# region ChartInfo
|
||||
|
||||
def get_chart_infos(self):
|
||||
stmt = select(ChartInfo)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_chart_infos_by_song_id(self, song_id: str):
|
||||
stmt = select(ChartInfo).where(ChartInfo.song_id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_chart_info(self, song_id: str, rating_class: int):
|
||||
stmt = select(ChartInfo).where(
|
||||
(ChartInfo.song_id == song_id) & (ChartInfo.rating_class == rating_class)
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# endregion
|
||||
|
||||
# region Chart
|
||||
|
||||
def get_charts_by_pack_id(self, pack_id: str):
|
||||
stmt = select(Chart).where(Chart.set == pack_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_charts_by_song_id(self, song_id: str):
|
||||
stmt = select(Chart).where(Chart.song_id == song_id)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_charts_by_constant(self, constant: int):
|
||||
stmt = select(Chart).where(Chart.constant == constant)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_chart(self, song_id: str, rating_class: int):
|
||||
stmt = select(Chart).where(
|
||||
(Chart.song_id == song_id) & (Chart.rating_class == rating_class)
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# endregion
|
||||
|
||||
# region Score
|
||||
|
||||
def get_scores(self):
|
||||
stmt = select(Score)
|
||||
with self.sessionmaker() as session:
|
||||
results = list(session.scalars(stmt))
|
||||
return results
|
||||
|
||||
def get_score(self, score_id: int):
|
||||
stmt = select(Score).where(Score.id == score_id)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
def get_score_best(self, song_id: str, rating_class: int):
|
||||
stmt = select(ScoreBest).where(
|
||||
(ScoreBest.song_id == song_id) & (ScoreBest.rating_class == rating_class)
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
def insert_score(self, score: Score):
|
||||
with self.sessionmaker() as session:
|
||||
session.add(score)
|
||||
session.commit()
|
||||
|
||||
def insert_scores(self, scores: Iterable[Score]):
|
||||
with self.sessionmaker() as session:
|
||||
session.add_all(scores)
|
||||
session.commit()
|
||||
|
||||
def update_score(self, score: Score):
|
||||
if score.id is None:
|
||||
raise ValueError(
|
||||
"Cannot determine which score to update, please specify `score.id`"
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
session.merge(score)
|
||||
session.commit()
|
||||
|
||||
def delete_score(self, score: Score):
|
||||
with self.sessionmaker() as session:
|
||||
session.delete(score)
|
||||
session.commit()
|
||||
|
||||
def recommend_charts(self, play_result: float, bounds: float = 0.1):
|
||||
base_constant = math.ceil(play_result * 10)
|
||||
|
||||
results = []
|
||||
results_id = []
|
||||
with self.sessionmaker() as session:
|
||||
for constant in range(base_constant - 20, base_constant + 1):
|
||||
# from Pure Memory(EX+) to AA
|
||||
score_modifier = (play_result * 10 - constant) / 10
|
||||
if score_modifier >= 2.0:
|
||||
min_score = 10000000
|
||||
elif score_modifier >= 1.0:
|
||||
min_score = 200000 * (score_modifier - 1) + 9800000
|
||||
else:
|
||||
min_score = 300000 * score_modifier + 9500000
|
||||
min_score = int(min_score)
|
||||
|
||||
charts = self.get_charts_by_constant(constant)
|
||||
for chart in charts:
|
||||
score_best_stmt = select(ScoreBest).where(
|
||||
(ScoreBest.song_id == chart.song_id)
|
||||
& (ScoreBest.rating_class == chart.rating_class)
|
||||
& (ScoreBest.score >= min_score)
|
||||
& (play_result - bounds < ScoreBest.potential)
|
||||
& (ScoreBest.potential < play_result + bounds)
|
||||
)
|
||||
if session.scalar(score_best_stmt):
|
||||
chart_id = f"{chart.song_id},{chart.rating_class}"
|
||||
if chart_id not in results_id:
|
||||
results.append(chart)
|
||||
results_id.append(chart_id)
|
||||
|
||||
return results
|
||||
|
||||
# endregion
|
||||
|
||||
def get_b30(self):
|
||||
stmt = select(CalculatedPotential.b30).select_from(CalculatedPotential)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result
|
||||
|
||||
# region COUNT
|
||||
|
||||
def __count_table(self, base: Type[DeclarativeBase]):
|
||||
stmt = select(func.count()).select_from(base)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result or 0
|
||||
|
||||
def __count_column(self, column: InstrumentedAttribute):
|
||||
stmt = select(func.count(column))
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result or 0
|
||||
|
||||
def count_packs(self):
|
||||
return self.__count_column(Pack.id)
|
||||
|
||||
def count_songs(self):
|
||||
return self.__count_column(Song.id)
|
||||
|
||||
def count_difficulties(self):
|
||||
return self.__count_table(Difficulty)
|
||||
|
||||
def count_chart_infos(self):
|
||||
return self.__count_table(ChartInfo)
|
||||
|
||||
def count_complete_chart_infos(self):
|
||||
stmt = (
|
||||
select(func.count())
|
||||
.select_from(ChartInfo)
|
||||
.where((ChartInfo.constant != None) & (ChartInfo.notes != None))
|
||||
)
|
||||
with self.sessionmaker() as session:
|
||||
result = session.scalar(stmt)
|
||||
return result or 0
|
||||
|
||||
def count_charts(self):
|
||||
return self.__count_table(Chart)
|
||||
|
||||
def count_scores(self):
|
||||
return self.__count_column(Score.id)
|
||||
|
||||
def count_scores_calculated(self):
|
||||
return self.__count_table(ScoreCalculated)
|
||||
|
||||
def count_scores_best(self):
|
||||
return self.__count_table(ScoreBest)
|
||||
|
||||
# endregion
|
||||
|
||||
# region export
|
||||
|
||||
def export_scores(self) -> List[ScoreExport]:
|
||||
scores = self.get_scores()
|
||||
return [exporters.score(score) for score in scores]
|
||||
|
||||
def generate_arcsong(self):
|
||||
with self.sessionmaker() as session:
|
||||
arcsong = ArcSongJsonBuilder(session).generate_arcsong_json()
|
||||
return arcsong
|
||||
|
||||
# endregion
|
0
src/arcaea_offline/database/__init__.py
Normal file
0
src/arcaea_offline/database/__init__.py
Normal file
1
src/arcaea_offline/database/migrations/README.md
Normal file
1
src/arcaea_offline/database/migrations/README.md
Normal file
@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
0
src/arcaea_offline/database/migrations/__init__.py
Normal file
0
src/arcaea_offline/database/migrations/__init__.py
Normal file
82
src/arcaea_offline/database/migrations/env.py
Normal file
82
src/arcaea_offline/database/migrations/env.py
Normal file
@ -0,0 +1,82 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from arcaea_offline.database.models._base import ModelBase
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = [ModelBase.metadata]
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
render_as_batch=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
render_as_batch=True,
|
||||
transaction_per_migration=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
28
src/arcaea_offline/database/migrations/legacies/v5.py
Normal file
28
src/arcaea_offline/database/migrations/legacies/v5.py
Normal file
@ -0,0 +1,28 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy.types import TypeDecorator
|
||||
|
||||
|
||||
class ForceTimezoneDateTime(TypeDecorator):
|
||||
"""
|
||||
Store timezone aware timestamps as timezone naive UTC
|
||||
|
||||
https://docs.sqlalchemy.org/en/20/core/custom_types.html#store-timezone-aware-timestamps-as-timezone-naive-utc
|
||||
"""
|
||||
|
||||
impl = DateTime
|
||||
cache_ok = True
|
||||
|
||||
def process_bind_param(self, value: Optional[datetime], dialect):
|
||||
if value is not None:
|
||||
if not value.tzinfo or value.tzinfo.utcoffset(value) is None:
|
||||
raise TypeError("datetime tzinfo is required")
|
||||
value = value.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
return value
|
||||
|
||||
def process_result_value(self, value: Optional[datetime], dialect):
|
||||
if value is not None:
|
||||
value = value.replace(tzinfo=timezone.utc)
|
||||
return value
|
26
src/arcaea_offline/database/migrations/script.py.mako
Normal file
26
src/arcaea_offline/database/migrations/script.py.mako
Normal file
@ -0,0 +1,26 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
@ -0,0 +1,506 @@
|
||||
"""v4 to v5
|
||||
|
||||
Revision ID: 0ca6733e40dc
|
||||
Revises: a3f9d48b7de3
|
||||
Create Date: 2025-05-31 11:38:25.575124
|
||||
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Sequence, Union
|
||||
from uuid import uuid4
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import context, op
|
||||
|
||||
from arcaea_offline.database.migrations.legacies.v5 import ForceTimezoneDateTime
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "0ca6733e40dc"
|
||||
down_revision: Union[str, None] = "a3f9d48b7de3"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade(
|
||||
*,
|
||||
data_migration: bool = True,
|
||||
data_migration_options: Any = None,
|
||||
) -> None:
|
||||
op.create_table(
|
||||
"property",
|
||||
sa.Column("key", sa.String(), nullable=False),
|
||||
sa.Column("value", sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("key", name=op.f("pk_property")),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"pack",
|
||||
sa.Column("id", sa.String(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=True),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("section", sa.String(), nullable=True),
|
||||
sa.Column(
|
||||
"is_world_extend", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.Column("plus_character", sa.Integer(), nullable=True),
|
||||
sa.Column("append_parent_id", sa.String(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["append_parent_id"],
|
||||
["pack.id"],
|
||||
name=op.f("fk_pack_append_parent_id_pack"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_pack")),
|
||||
)
|
||||
with op.batch_alter_table("pack", schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f("ix_pack_name"), ["name"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"pack_localization",
|
||||
sa.Column("id", sa.String(), nullable=False),
|
||||
sa.Column("lang", sa.String(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=True),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"],
|
||||
["pack.id"],
|
||||
name=op.f("fk_pack_localization_id_pack"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", "lang", name=op.f("pk_pack_localization")),
|
||||
)
|
||||
op.create_table(
|
||||
"song",
|
||||
sa.Column("pack_id", sa.String(), nullable=False),
|
||||
sa.Column("id", sa.String(), nullable=False),
|
||||
sa.Column("idx", sa.Integer(), nullable=True),
|
||||
sa.Column("title", sa.String(), nullable=True),
|
||||
sa.Column("artist", sa.String(), nullable=True),
|
||||
sa.Column(
|
||||
"is_deleted", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.Column("added_at", ForceTimezoneDateTime(), nullable=False),
|
||||
sa.Column("version", sa.String(), nullable=True),
|
||||
sa.Column("bpm", sa.String(), nullable=True),
|
||||
sa.Column("bpm_base", sa.Numeric(), nullable=True),
|
||||
sa.Column(
|
||||
"is_remote", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"is_unlockable_in_world",
|
||||
sa.Boolean(),
|
||||
server_default=sa.text("0"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"is_beyond_unlock_state_local",
|
||||
sa.Boolean(),
|
||||
server_default=sa.text("0"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("purchase", sa.String(), nullable=True),
|
||||
sa.Column("category", sa.String(), nullable=True),
|
||||
sa.Column("side", sa.Integer(), nullable=True),
|
||||
sa.Column("bg", sa.String(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.String(), nullable=True),
|
||||
sa.Column("bg_day", sa.String(), nullable=True),
|
||||
sa.Column("bg_night", sa.String(), nullable=True),
|
||||
sa.Column("source", sa.String(), nullable=True),
|
||||
sa.Column("source_copyright", sa.String(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["pack_id"],
|
||||
["pack.id"],
|
||||
name=op.f("fk_song_pack_id_pack"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_song")),
|
||||
)
|
||||
with op.batch_alter_table("song", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_song_added_at"), ["added_at"], unique=False
|
||||
)
|
||||
batch_op.create_index(batch_op.f("ix_song_artist"), ["artist"], unique=False)
|
||||
batch_op.create_index(batch_op.f("ix_song_title"), ["title"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"difficulty",
|
||||
sa.Column("song_id", sa.String(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("rating", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"is_rating_plus", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.Column("chart_designer", sa.String(), nullable=True),
|
||||
sa.Column("jacket_designer", sa.String(), nullable=True),
|
||||
sa.Column(
|
||||
"has_overriding_audio",
|
||||
sa.Boolean(),
|
||||
server_default=sa.text("0"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"has_overriding_jacket",
|
||||
sa.Boolean(),
|
||||
server_default=sa.text("0"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("jacket_night", sa.String(), nullable=True),
|
||||
sa.Column("title", sa.String(), nullable=True),
|
||||
sa.Column("artist", sa.String(), nullable=True),
|
||||
sa.Column("bg", sa.String(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.String(), nullable=True),
|
||||
sa.Column("bpm", sa.String(), nullable=True),
|
||||
sa.Column("bpm_base", sa.Numeric(), nullable=True),
|
||||
sa.Column("added_at", ForceTimezoneDateTime(), nullable=True),
|
||||
sa.Column("version", sa.String(), nullable=True),
|
||||
sa.Column(
|
||||
"is_legacy11", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id"],
|
||||
["song.id"],
|
||||
name=op.f("fk_difficulty_song_id_song"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("song_id", "rating_class", name=op.f("pk_difficulty")),
|
||||
)
|
||||
op.create_table(
|
||||
"song_localization",
|
||||
sa.Column("id", sa.String(), nullable=False),
|
||||
sa.Column("lang", sa.String(), nullable=False),
|
||||
sa.Column("title", sa.String(), nullable=True),
|
||||
sa.Column("source", sa.String(), nullable=True),
|
||||
sa.Column(
|
||||
"has_jacket", sa.Boolean(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"],
|
||||
["song.id"],
|
||||
name=op.f("fk_song_localization_id_song"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", "lang", name=op.f("pk_song_localization")),
|
||||
)
|
||||
op.create_table(
|
||||
"chart_info",
|
||||
sa.Column("song_id", sa.String(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("constant", sa.Numeric(), nullable=False),
|
||||
sa.Column("notes", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"added_at",
|
||||
ForceTimezoneDateTime(),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("version", sa.String(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id", "rating_class"],
|
||||
["difficulty.song_id", "difficulty.rating_class"],
|
||||
name=op.f("fk_chart_info_song_id_difficulty"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"song_id", "rating_class", "added_at", name=op.f("pk_chart_info")
|
||||
),
|
||||
)
|
||||
op.create_table(
|
||||
"difficulty_localization",
|
||||
sa.Column("song_id", sa.String(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("lang", sa.String(), nullable=False),
|
||||
sa.Column("title", sa.String(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id", "rating_class"],
|
||||
["difficulty.song_id", "difficulty.rating_class"],
|
||||
name=op.f("fk_difficulty_localization_song_id_difficulty"),
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"song_id", "rating_class", "lang", name=op.f("pk_difficulty_localization")
|
||||
),
|
||||
)
|
||||
|
||||
op.drop_table("properties")
|
||||
op.drop_table("packs")
|
||||
op.drop_table("packs_localized")
|
||||
op.drop_table("difficulties")
|
||||
op.drop_table("songs")
|
||||
op.drop_table("songs_localized")
|
||||
op.drop_table("charts")
|
||||
op.drop_table("charts_info")
|
||||
op.drop_table("difficulties_localized")
|
||||
|
||||
op.rename_table("scores", "scores_old")
|
||||
play_result_tbl = op.create_table(
|
||||
"play_result",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("uuid", sa.Uuid(), nullable=False),
|
||||
sa.Column("song_id", sa.String(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("played_at", ForceTimezoneDateTime(), nullable=True),
|
||||
sa.Column("score", sa.Integer(), nullable=False),
|
||||
sa.Column("pure", sa.Integer(), nullable=True),
|
||||
sa.Column("pure_early", sa.Integer(), nullable=True),
|
||||
sa.Column("pure_late", sa.Integer(), nullable=True),
|
||||
sa.Column("far", sa.Integer(), nullable=True),
|
||||
sa.Column("far_early", sa.Integer(), nullable=True),
|
||||
sa.Column("far_late", sa.Integer(), nullable=True),
|
||||
sa.Column("lost", sa.Integer(), nullable=True),
|
||||
sa.Column("max_recall", sa.Integer(), nullable=True),
|
||||
sa.Column("clear_type", sa.Integer(), nullable=True),
|
||||
sa.Column("modifier", sa.Integer(), nullable=True),
|
||||
sa.Column("comment", sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_play_result")),
|
||||
sa.UniqueConstraint("uuid", name=op.f("uq_play_result_uuid")),
|
||||
)
|
||||
|
||||
if data_migration:
|
||||
conn = op.get_bind()
|
||||
query = conn.execute(
|
||||
sa.text(
|
||||
"SELECT id, song_id, rating_class, score, pure, far, lost, "
|
||||
" `date`, max_recall, modifier, clear_type, comment "
|
||||
"FROM scores_old"
|
||||
)
|
||||
)
|
||||
batch_size = 30
|
||||
|
||||
while True:
|
||||
rows = query.fetchmany(batch_size)
|
||||
if not rows:
|
||||
break
|
||||
|
||||
rows_to_insert = []
|
||||
for row in rows:
|
||||
result = row._asdict()
|
||||
|
||||
date = result.pop("date")
|
||||
result["uuid"] = uuid4()
|
||||
result["played_at"] = (
|
||||
datetime.fromtimestamp(date, tz=timezone.utc)
|
||||
if date is not None
|
||||
else None
|
||||
)
|
||||
rows_to_insert.append(result)
|
||||
|
||||
conn.execute(sa.insert(play_result_tbl), rows_to_insert)
|
||||
|
||||
op.drop_table("scores_old")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
raise NotImplementedError(
|
||||
f"Downgrade not supported! ({context.get_context().get_current_revision()})"
|
||||
)
|
||||
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"difficulties_localized",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.INTEGER(), nullable=False),
|
||||
sa.Column("title_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["rating_class"],
|
||||
["difficulties.rating_class"],
|
||||
name=op.f("fk_difficulties_localized_rating_class_difficulties"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id"],
|
||||
["difficulties.song_id"],
|
||||
name=op.f("fk_difficulties_localized_song_id_difficulties"),
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"song_id", "rating_class", name=op.f("pk_difficulties_localized")
|
||||
),
|
||||
)
|
||||
op.create_table(
|
||||
"charts_info",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.INTEGER(), nullable=False),
|
||||
sa.Column("constant", sa.INTEGER(), nullable=False),
|
||||
sa.Column("notes", sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["rating_class"],
|
||||
["difficulties.rating_class"],
|
||||
name=op.f("fk_charts_info_rating_class_difficulties"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id"],
|
||||
["difficulties.song_id"],
|
||||
name=op.f("fk_charts_info_song_id_difficulties"),
|
||||
),
|
||||
sa.PrimaryKeyConstraint("song_id", "rating_class", name=op.f("pk_charts_info")),
|
||||
)
|
||||
op.create_table(
|
||||
"charts",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.INTEGER(), nullable=False),
|
||||
sa.Column("name_en", sa.TEXT(), nullable=False),
|
||||
sa.Column("name_jp", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist", sa.TEXT(), nullable=False),
|
||||
sa.Column("bpm", sa.TEXT(), nullable=False),
|
||||
sa.Column("bpm_base", sa.REAL(), nullable=False),
|
||||
sa.Column("package_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("time", sa.INTEGER(), nullable=True),
|
||||
sa.Column("side", sa.INTEGER(), nullable=False),
|
||||
sa.Column("world_unlock", sa.BOOLEAN(), nullable=False),
|
||||
sa.Column("remote_download", sa.BOOLEAN(), nullable=True),
|
||||
sa.Column("bg", sa.TEXT(), nullable=False),
|
||||
sa.Column("date", sa.INTEGER(), nullable=False),
|
||||
sa.Column("version", sa.TEXT(), nullable=False),
|
||||
sa.Column("difficulty", sa.INTEGER(), nullable=False),
|
||||
sa.Column("rating", sa.INTEGER(), nullable=False),
|
||||
sa.Column("note", sa.INTEGER(), nullable=False),
|
||||
sa.Column("chart_designer", sa.TEXT(), nullable=True),
|
||||
sa.Column("jacket_designer", sa.TEXT(), nullable=True),
|
||||
sa.Column("jacket_override", sa.BOOLEAN(), nullable=False),
|
||||
sa.Column("audio_override", sa.BOOLEAN(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("song_id", "rating_class"),
|
||||
)
|
||||
op.create_table(
|
||||
"songs_localized",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("title_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_title_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_title_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_title_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_title_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_artist_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_artist_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_artist_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_artist_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"], ["songs.id"], name=op.f("fk_songs_localized_id_songs")
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_songs_localized")),
|
||||
)
|
||||
op.create_table(
|
||||
"packs",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("name", sa.TEXT(), nullable=False),
|
||||
sa.Column("description", sa.TEXT(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name="fk_packs"),
|
||||
)
|
||||
op.create_table(
|
||||
"properties",
|
||||
sa.Column("key", sa.TEXT(), nullable=False),
|
||||
sa.Column("value", sa.TEXT(), nullable=False),
|
||||
sa.UniqueConstraint("key"),
|
||||
)
|
||||
op.create_table(
|
||||
"songs",
|
||||
sa.Column("idx", sa.INTEGER(), nullable=False),
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("title", sa.TEXT(), nullable=False),
|
||||
sa.Column("artist", sa.TEXT(), nullable=False),
|
||||
sa.Column("set", sa.TEXT(), nullable=False),
|
||||
sa.Column("bpm", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm_base", sa.FLOAT(), nullable=True),
|
||||
sa.Column("audio_preview", sa.INTEGER(), nullable=True),
|
||||
sa.Column("audio_preview_end", sa.INTEGER(), nullable=True),
|
||||
sa.Column("side", sa.INTEGER(), nullable=True),
|
||||
sa.Column("version", sa.TEXT(), nullable=True),
|
||||
sa.Column("date", sa.INTEGER(), nullable=True),
|
||||
sa.Column("bg", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_day", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_night", sa.TEXT(), nullable=True),
|
||||
sa.Column("source", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_copyright", sa.TEXT(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("songs")),
|
||||
)
|
||||
op.create_table(
|
||||
"difficulties",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.INTEGER(), nullable=False),
|
||||
sa.Column("rating", sa.INTEGER(), nullable=False),
|
||||
sa.Column("rating_plus", sa.BOOLEAN(), nullable=False),
|
||||
sa.Column("chart_designer", sa.TEXT(), nullable=True),
|
||||
sa.Column("jacket_desginer", sa.TEXT(), nullable=True),
|
||||
sa.Column("audio_override", sa.BOOLEAN(), nullable=False),
|
||||
sa.Column("jacket_override", sa.BOOLEAN(), nullable=False),
|
||||
sa.Column("jacket_night", sa.TEXT(), nullable=True),
|
||||
sa.Column("title", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm_base", sa.FLOAT(), nullable=True),
|
||||
sa.Column("version", sa.TEXT(), nullable=True),
|
||||
sa.Column("date", sa.INTEGER(), nullable=True),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"song_id", "rating_class", name=op.f("pk_difficulties")
|
||||
),
|
||||
)
|
||||
op.create_table(
|
||||
"packs_localized",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("name_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"], ["packs.id"], name=op.f("fk_packs_localized_id_packs")
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_packs_localized")),
|
||||
)
|
||||
op.create_table(
|
||||
"scores",
|
||||
sa.Column("id", sa.INTEGER(), nullable=False),
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.INTEGER(), nullable=False),
|
||||
sa.Column("score", sa.INTEGER(), nullable=False),
|
||||
sa.Column("pure", sa.INTEGER(), nullable=True),
|
||||
sa.Column("far", sa.INTEGER(), nullable=True),
|
||||
sa.Column("lost", sa.INTEGER(), nullable=True),
|
||||
sa.Column("date", sa.INTEGER(), nullable=True),
|
||||
sa.Column("max_recall", sa.INTEGER(), nullable=True),
|
||||
sa.Column("modifier", sa.INTEGER(), nullable=True),
|
||||
sa.Column("clear_type", sa.INTEGER(), nullable=True),
|
||||
sa.Column("comment", sa.TEXT(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.drop_table("difficulty_localization")
|
||||
op.drop_table("chart_info")
|
||||
op.drop_table("song_localization")
|
||||
op.drop_table("difficulty")
|
||||
with op.batch_alter_table("song", schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f("ix_song_title"))
|
||||
batch_op.drop_index(batch_op.f("ix_song_artist"))
|
||||
batch_op.drop_index(batch_op.f("ix_song_added_at"))
|
||||
|
||||
op.drop_table("song")
|
||||
op.drop_table("pack_localization")
|
||||
op.drop_table("property")
|
||||
op.drop_table("play_result")
|
||||
with op.batch_alter_table("pack", schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f("ix_pack_name"))
|
||||
|
||||
op.drop_table("pack")
|
||||
# ### end Alembic commands ###
|
@ -0,0 +1,275 @@
|
||||
"""v1 to v4
|
||||
|
||||
Revision ID: a3f9d48b7de3
|
||||
Revises:
|
||||
Create Date: 2024-11-24 00:03:07.697165
|
||||
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import Mapping, Optional, Sequence, TypedDict, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import context, op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "a3f9d48b7de3"
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
class V4DataMigrationOptions(TypedDict):
|
||||
threshold_date: Optional[datetime]
|
||||
|
||||
|
||||
def _data_migration_options(user_input: Optional[Mapping]):
|
||||
options: V4DataMigrationOptions = {
|
||||
"threshold_date": datetime(year=2017, month=1, day=23, tzinfo=timezone.utc),
|
||||
}
|
||||
|
||||
if user_input is None:
|
||||
return options
|
||||
|
||||
if not isinstance(user_input, dict):
|
||||
raise TypeError("v4 migration: data migration options should be a dict object")
|
||||
|
||||
threshold_date = user_input.get("threshold_date")
|
||||
if threshold_date is not None and not isinstance(threshold_date, datetime):
|
||||
raise ValueError(
|
||||
"v4 migration: threshold_date should be None or a datetime.datetime object"
|
||||
)
|
||||
options["threshold_date"] = threshold_date
|
||||
|
||||
return options
|
||||
|
||||
|
||||
def upgrade(
|
||||
*,
|
||||
data_migration: bool = True,
|
||||
data_migration_options: Optional[V4DataMigrationOptions] = None,
|
||||
) -> None:
|
||||
data_migration_options = _data_migration_options(data_migration_options)
|
||||
threshold_date = data_migration_options["threshold_date"]
|
||||
|
||||
op.create_table(
|
||||
"difficulties",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("rating", sa.Integer(), nullable=False),
|
||||
sa.Column("rating_plus", sa.Boolean(), nullable=False),
|
||||
sa.Column("chart_designer", sa.TEXT(), nullable=True),
|
||||
sa.Column("jacket_desginer", sa.TEXT(), nullable=True),
|
||||
sa.Column("audio_override", sa.Boolean(), nullable=False),
|
||||
sa.Column("jacket_override", sa.Boolean(), nullable=False),
|
||||
sa.Column("jacket_night", sa.TEXT(), nullable=True),
|
||||
sa.Column("title", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm_base", sa.Float(), nullable=True),
|
||||
sa.Column("version", sa.TEXT(), nullable=True),
|
||||
sa.Column("date", sa.Integer(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("song_id", "rating_class", name="pk_difficulties"),
|
||||
)
|
||||
op.create_table(
|
||||
"packs",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("name", sa.TEXT(), nullable=False),
|
||||
sa.Column("description", sa.TEXT(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name="fk_packs"),
|
||||
)
|
||||
op.create_table(
|
||||
"songs",
|
||||
sa.Column("idx", sa.Integer(), nullable=False),
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("title", sa.TEXT(), nullable=False),
|
||||
sa.Column("artist", sa.TEXT(), nullable=False),
|
||||
sa.Column("set", sa.TEXT(), nullable=False),
|
||||
sa.Column("bpm", sa.TEXT(), nullable=True),
|
||||
sa.Column("bpm_base", sa.Float(), nullable=True),
|
||||
sa.Column("audio_preview", sa.Integer(), nullable=True),
|
||||
sa.Column("audio_preview_end", sa.Integer(), nullable=True),
|
||||
sa.Column("side", sa.Integer(), nullable=True),
|
||||
sa.Column("version", sa.TEXT(), nullable=True),
|
||||
sa.Column("date", sa.Integer(), nullable=True),
|
||||
sa.Column("bg", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_inverse", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_day", sa.TEXT(), nullable=True),
|
||||
sa.Column("bg_night", sa.TEXT(), nullable=True),
|
||||
sa.Column("source", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_copyright", sa.TEXT(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name="songs"),
|
||||
)
|
||||
op.create_table(
|
||||
"charts_info",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"constant",
|
||||
sa.Integer(),
|
||||
nullable=False,
|
||||
comment="real_constant * 10. For example, Crimson Throne [FTR] is 10.4, then store 104.",
|
||||
),
|
||||
sa.Column("notes", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["rating_class"],
|
||||
["difficulties.rating_class"],
|
||||
name="fk_charts_info_rating_class_difficulties",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id"],
|
||||
["difficulties.song_id"],
|
||||
name="fk_charts_info_song_id_difficulties",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("song_id", "rating_class", name="pk_charts_info"),
|
||||
)
|
||||
op.create_table(
|
||||
"difficulties_localized",
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("title_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("artist_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["rating_class"],
|
||||
["difficulties.rating_class"],
|
||||
name="fk_difficulties_localized_rating_class_difficulties",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["song_id"],
|
||||
["difficulties.song_id"],
|
||||
name="fk_difficulties_localized_song_id_difficulties",
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"song_id", "rating_class", name="pk_difficulties_localized"
|
||||
),
|
||||
)
|
||||
op.create_table(
|
||||
"packs_localized",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("name_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("name_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("description_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"],
|
||||
["packs.id"],
|
||||
name="fk_packs_localized_id_packs",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name="pk_packs_localized"),
|
||||
)
|
||||
op.create_table(
|
||||
"songs_localized",
|
||||
sa.Column("id", sa.TEXT(), nullable=False),
|
||||
sa.Column("title_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("title_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.Column("search_title_ja", sa.TEXT(), nullable=True, comment="JSON array"),
|
||||
sa.Column("search_title_ko", sa.TEXT(), nullable=True, comment="JSON array"),
|
||||
sa.Column(
|
||||
"search_title_zh_hans", sa.TEXT(), nullable=True, comment="JSON array"
|
||||
),
|
||||
sa.Column(
|
||||
"search_title_zh_hant", sa.TEXT(), nullable=True, comment="JSON array"
|
||||
),
|
||||
sa.Column("search_artist_ja", sa.TEXT(), nullable=True, comment="JSON array"),
|
||||
sa.Column("search_artist_ko", sa.TEXT(), nullable=True, comment="JSON array"),
|
||||
sa.Column(
|
||||
"search_artist_zh_hans", sa.TEXT(), nullable=True, comment="JSON array"
|
||||
),
|
||||
sa.Column(
|
||||
"search_artist_zh_hant", sa.TEXT(), nullable=True, comment="JSON array"
|
||||
),
|
||||
sa.Column("source_ja", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_ko", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_zh_hans", sa.TEXT(), nullable=True),
|
||||
sa.Column("source_zh_hant", sa.TEXT(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["id"],
|
||||
["songs.id"],
|
||||
name="fk_songs_localized_id_songs",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name="pk_songs_localized"),
|
||||
)
|
||||
op.drop_table("aliases")
|
||||
op.drop_table("packages")
|
||||
op.execute(sa.text("DROP VIEW IF EXISTS bests"))
|
||||
op.execute(sa.text("DROP VIEW IF EXISTS calculated"))
|
||||
op.execute(sa.text("DROP VIEW IF EXISTS calculated_potential"))
|
||||
op.execute(sa.text("DROP VIEW IF EXISTS song_id_names"))
|
||||
|
||||
op.rename_table("scores", "scores_old")
|
||||
scores_tbl = op.create_table(
|
||||
"scores",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, primary_key=True),
|
||||
sa.Column("song_id", sa.TEXT(), nullable=False),
|
||||
sa.Column("rating_class", sa.Integer(), nullable=False),
|
||||
sa.Column("score", sa.Integer(), nullable=False),
|
||||
sa.Column("pure", sa.Integer()),
|
||||
sa.Column("far", sa.Integer()),
|
||||
sa.Column("lost", sa.Integer()),
|
||||
sa.Column("date", sa.Integer()),
|
||||
sa.Column("max_recall", sa.Integer()),
|
||||
sa.Column("modifier", sa.Integer(), comment="0: NORMAL, 1: EASY, 2: HARD"),
|
||||
sa.Column(
|
||||
"clear_type",
|
||||
sa.Integer(),
|
||||
comment="0: TRACK LOST, 1: NORMAL CLEAR, 2: FULL RECALL, "
|
||||
"3: PURE MEMORY, 4: EASY CLEAR, 5: HARD CLEAR",
|
||||
),
|
||||
sa.Column("comment", sa.TEXT()),
|
||||
)
|
||||
if data_migration:
|
||||
conn = op.get_bind()
|
||||
query = conn.execute(
|
||||
sa.text(
|
||||
"SELECT id, song_id, rating_class, score, time, pure, far, lost, max_recall, clear_type "
|
||||
"FROM scores_old"
|
||||
)
|
||||
)
|
||||
batch_size = 30
|
||||
|
||||
while True:
|
||||
rows = query.fetchmany(batch_size)
|
||||
if not rows:
|
||||
break
|
||||
|
||||
rows_to_insert = []
|
||||
|
||||
for row in rows:
|
||||
result = row._asdict()
|
||||
result["date"] = datetime.fromtimestamp(
|
||||
result.pop("time"), tz=timezone.utc
|
||||
)
|
||||
|
||||
if threshold_date is not None and result["date"] <= threshold_date:
|
||||
result["date"] = None
|
||||
|
||||
result["date"] = (
|
||||
int(result["date"].timestamp())
|
||||
if result["date"] is not None
|
||||
else None
|
||||
)
|
||||
rows_to_insert.append(result)
|
||||
|
||||
conn.execute(sa.insert(scores_tbl), rows_to_insert)
|
||||
|
||||
op.drop_table("scores_old")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
raise NotImplementedError(
|
||||
f"Downgrade not supported! ({context.get_context().get_current_revision()})"
|
||||
)
|
32
src/arcaea_offline/database/models/__init__.py
Normal file
32
src/arcaea_offline/database/models/__init__.py
Normal file
@ -0,0 +1,32 @@
|
||||
from ._base import ModelBase, ModelViewBase
|
||||
from .chart_info import ChartInfo
|
||||
from .config import Property
|
||||
from .difficulty import Difficulty, DifficultyLocalization
|
||||
from .pack import Pack, PackLocalization
|
||||
from .song import Song, SongLocalization
|
||||
|
||||
from .chart import Chart # isort: skip
|
||||
from .play_result import (
|
||||
CalculatedPotential,
|
||||
PlayResult,
|
||||
PlayResultBest,
|
||||
PlayResultCalculated,
|
||||
) # isort: skip
|
||||
|
||||
__all__ = [
|
||||
"CalculatedPotential",
|
||||
"Chart",
|
||||
"ChartInfo",
|
||||
"Difficulty",
|
||||
"DifficultyLocalization",
|
||||
"ModelBase",
|
||||
"ModelViewBase",
|
||||
"Pack",
|
||||
"PackLocalization",
|
||||
"PlayResult",
|
||||
"PlayResultBest",
|
||||
"PlayResultCalculated",
|
||||
"Property",
|
||||
"Song",
|
||||
"SongLocalization",
|
||||
]
|
@ -1,11 +1,39 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy.orm.exc import DetachedInstanceError
|
||||
|
||||
from ._types import ForceTimezoneDateTime
|
||||
|
||||
TYPE_ANNOTATION_MAP = {
|
||||
datetime: ForceTimezoneDateTime,
|
||||
}
|
||||
|
||||
|
||||
class ModelBase(DeclarativeBase):
|
||||
type_annotation_map = TYPE_ANNOTATION_MAP
|
||||
metadata = MetaData(
|
||||
naming_convention={
|
||||
"ix": "ix_%(column_0_label)s",
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_`%(constraint_name)s`",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ModelViewBase(DeclarativeBase):
|
||||
type_annotation_map = TYPE_ANNOTATION_MAP
|
||||
|
||||
|
||||
class ReprHelper:
|
||||
# pylint: disable=no-member
|
||||
|
||||
def _repr(self, **kwargs) -> str:
|
||||
"""
|
||||
Helper for __repr__
|
||||
SQLAlchemy model __repr__ helper
|
||||
|
||||
https://stackoverflow.com/a/55749579/16484891
|
||||
|
||||
@ -20,8 +48,9 @@ class ReprHelper:
|
||||
field_strings.append(f"{key}=DetachedInstanceError")
|
||||
else:
|
||||
at_least_one_attached_attribute = True
|
||||
|
||||
if at_least_one_attached_attribute:
|
||||
return f"<{self.__class__.__name__}({','.join(field_strings)})>"
|
||||
return f"<{self.__class__.__name__}({', '.join(field_strings)})>"
|
||||
return f"<{self.__class__.__name__} {id(self)}>"
|
||||
|
||||
def __repr__(self):
|
28
src/arcaea_offline/database/models/_types.py
Normal file
28
src/arcaea_offline/database/models/_types.py
Normal file
@ -0,0 +1,28 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy.types import TypeDecorator
|
||||
|
||||
|
||||
class ForceTimezoneDateTime(TypeDecorator):
|
||||
"""
|
||||
Store timezone aware timestamps as timezone naive UTC
|
||||
|
||||
https://docs.sqlalchemy.org/en/20/core/custom_types.html#store-timezone-aware-timestamps-as-timezone-naive-utc
|
||||
"""
|
||||
|
||||
impl = DateTime
|
||||
cache_ok = True
|
||||
|
||||
def process_bind_param(self, value: Optional[datetime], dialect):
|
||||
if value is not None:
|
||||
if not value.tzinfo or value.tzinfo.utcoffset(value) is None:
|
||||
raise TypeError("datetime tzinfo is required")
|
||||
value = value.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
return value
|
||||
|
||||
def process_result_value(self, value: Optional[datetime], dialect):
|
||||
if value is not None:
|
||||
value = value.replace(tzinfo=timezone.utc)
|
||||
return value
|
85
src/arcaea_offline/database/models/chart.py
Normal file
85
src/arcaea_offline/database/models/chart.py
Normal file
@ -0,0 +1,85 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Mapped
|
||||
from sqlalchemy_utils import create_view
|
||||
|
||||
from ._base import ModelBase, ModelViewBase, ReprHelper
|
||||
from .chart_info import ChartInfo
|
||||
from .difficulty import Difficulty
|
||||
from .song import Song
|
||||
|
||||
|
||||
class Chart(ModelBase, ReprHelper):
|
||||
__tablename__ = "charts"
|
||||
|
||||
song_idx: Mapped[int]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
rating: Mapped[int]
|
||||
is_rating_plus: Mapped[bool]
|
||||
title: Mapped[str]
|
||||
artist: Mapped[str]
|
||||
pack_id: Mapped[str]
|
||||
bpm: Mapped[Optional[str]]
|
||||
bpm_base: Mapped[Optional[float]]
|
||||
audio_preview: Mapped[Optional[int]]
|
||||
audio_preview_end: Mapped[Optional[int]]
|
||||
side: Mapped[Optional[int]]
|
||||
version: Mapped[Optional[str]]
|
||||
added_at: Mapped[Optional[datetime]]
|
||||
bg: Mapped[Optional[str]]
|
||||
bg_inverse: Mapped[Optional[str]]
|
||||
bg_day: Mapped[Optional[str]]
|
||||
bg_night: Mapped[Optional[str]]
|
||||
source: Mapped[Optional[str]]
|
||||
source_copyright: Mapped[Optional[str]]
|
||||
chart_designer: Mapped[Optional[str]]
|
||||
jacket_desginer: Mapped[Optional[str]]
|
||||
has_overriding_audio: Mapped[bool]
|
||||
has_overriding_jacket: Mapped[bool]
|
||||
jacket_night: Mapped[Optional[str]]
|
||||
constant: Mapped[int]
|
||||
notes: Mapped[Optional[int]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
Song.idx.label("song_idx"),
|
||||
Difficulty.song_id,
|
||||
Difficulty.rating_class,
|
||||
Difficulty.rating,
|
||||
Difficulty.is_rating_plus,
|
||||
func.coalesce(Difficulty.title, Song.title).label("title"),
|
||||
func.coalesce(Difficulty.artist, Song.artist).label("artist"),
|
||||
Song.pack_id,
|
||||
func.coalesce(Difficulty.bpm, Song.bpm).label("bpm"),
|
||||
func.coalesce(Difficulty.bpm_base, Song.bpm_base).label("bpm_base"),
|
||||
Song.side,
|
||||
func.coalesce(Difficulty.version, Song.version).label("version"),
|
||||
func.coalesce(Difficulty.added_at, Song.added_at).label("added_at"),
|
||||
func.coalesce(Difficulty.bg, Song.bg).label("bg"),
|
||||
func.coalesce(Difficulty.bg_inverse, Song.bg_inverse).label("bg_inverse"),
|
||||
Song.bg_day,
|
||||
Song.bg_night,
|
||||
Song.source,
|
||||
Song.source_copyright,
|
||||
Difficulty.chart_designer,
|
||||
Difficulty.jacket_designer,
|
||||
Difficulty.has_overriding_audio,
|
||||
Difficulty.has_overriding_jacket,
|
||||
Difficulty.jacket_night,
|
||||
ChartInfo.constant,
|
||||
ChartInfo.notes,
|
||||
)
|
||||
.select_from(Difficulty)
|
||||
.join(
|
||||
ChartInfo,
|
||||
(Difficulty.song_id == ChartInfo.song_id)
|
||||
& (Difficulty.rating_class == ChartInfo.rating_class),
|
||||
)
|
||||
.join(Song, Difficulty.song_id == Song.id),
|
||||
metadata=ModelViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
33
src/arcaea_offline/database/models/chart_info.py
Normal file
33
src/arcaea_offline/database/models/chart_info.py
Normal file
@ -0,0 +1,33 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import ForeignKeyConstraint, Integer, Numeric, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from ._base import ModelBase, ReprHelper
|
||||
from ._types import ForceTimezoneDateTime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .difficulty import Difficulty
|
||||
|
||||
|
||||
class ChartInfo(ModelBase, ReprHelper):
|
||||
__tablename__ = "chart_info"
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(
|
||||
["song_id", "rating_class"],
|
||||
["difficulty.song_id", "difficulty.rating_class"],
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
)
|
||||
|
||||
difficulty: Mapped["Difficulty"] = relationship(back_populates="chart_info_list")
|
||||
|
||||
song_id: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
rating_class: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
constant: Mapped[Decimal] = mapped_column(Numeric, nullable=False)
|
||||
notes: Mapped[int] = mapped_column(Integer)
|
||||
added_at: Mapped[datetime] = mapped_column(ForceTimezoneDateTime, primary_key=True)
|
||||
version: Mapped[Optional[str]] = mapped_column(String)
|
12
src/arcaea_offline/database/models/config.py
Normal file
12
src/arcaea_offline/database/models/config.py
Normal file
@ -0,0 +1,12 @@
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from ._base import ModelBase, ReprHelper
|
||||
|
||||
__all__ = ["Property"]
|
||||
|
||||
|
||||
class Property(ModelBase, ReprHelper):
|
||||
__tablename__ = "property"
|
||||
|
||||
key: Mapped[str] = mapped_column(primary_key=True)
|
||||
value: Mapped[str] = mapped_column()
|
93
src/arcaea_offline/database/models/difficulty.py
Normal file
93
src/arcaea_offline/database/models/difficulty.py
Normal file
@ -0,0 +1,93 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
ForeignKey,
|
||||
ForeignKeyConstraint,
|
||||
Integer,
|
||||
Numeric,
|
||||
String,
|
||||
text,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from ._base import ModelBase, ReprHelper
|
||||
from ._types import ForceTimezoneDateTime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .chart_info import ChartInfo
|
||||
from .song import Song
|
||||
|
||||
|
||||
class Difficulty(ModelBase, ReprHelper):
|
||||
__tablename__ = "difficulty"
|
||||
|
||||
song_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("song.id", onupdate="CASCADE", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
)
|
||||
song: Mapped["Song"] = relationship(back_populates="difficulties")
|
||||
localization_entries: Mapped[list["DifficultyLocalization"]] = relationship(
|
||||
back_populates="difficulty",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
chart_info_list: Mapped[list["ChartInfo"]] = relationship(
|
||||
back_populates="difficulty",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
|
||||
rating_class: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
|
||||
rating: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
is_rating_plus: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
|
||||
chart_designer: Mapped[Optional[str]] = mapped_column(String)
|
||||
jacket_designer: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
has_overriding_audio: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
has_overriding_jacket: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
jacket_night: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
title: Mapped[Optional[str]] = mapped_column(String)
|
||||
artist: Mapped[Optional[str]] = mapped_column(String)
|
||||
bg: Mapped[Optional[str]] = mapped_column(String)
|
||||
bg_inverse: Mapped[Optional[str]] = mapped_column(String)
|
||||
bpm: Mapped[Optional[str]] = mapped_column(String)
|
||||
bpm_base: Mapped[Optional[Decimal]] = mapped_column(Numeric(asdecimal=True))
|
||||
added_at: Mapped[Optional[datetime]] = mapped_column(ForceTimezoneDateTime)
|
||||
version: Mapped[Optional[str]] = mapped_column(String)
|
||||
is_legacy11: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
|
||||
|
||||
class DifficultyLocalization(ModelBase, ReprHelper):
|
||||
__tablename__ = "difficulty_localization"
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(
|
||||
["song_id", "rating_class"],
|
||||
["difficulty.song_id", "difficulty.rating_class"],
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
)
|
||||
|
||||
difficulty: Mapped["Difficulty"] = relationship(
|
||||
back_populates="localization_entries"
|
||||
)
|
||||
song_id: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
rating_class: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
|
||||
lang: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
title: Mapped[Optional[str]] = mapped_column(String)
|
||||
artist: Mapped[Optional[str]] = mapped_column(String)
|
61
src/arcaea_offline/database/models/pack.py
Normal file
61
src/arcaea_offline/database/models/pack.py
Normal file
@ -0,0 +1,61 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, Integer, String, Text, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from ._base import ModelBase, ReprHelper
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .song import Song
|
||||
|
||||
|
||||
class Pack(ModelBase, ReprHelper):
|
||||
__tablename__ = "pack"
|
||||
|
||||
songs: Mapped[list["Song"]] = relationship(
|
||||
back_populates="pack",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
localized_entries: Mapped[list["PackLocalization"]] = relationship(
|
||||
back_populates="pack",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column(String, index=True)
|
||||
description: Mapped[Optional[str]] = mapped_column(Text)
|
||||
section: Mapped[Optional[str]] = mapped_column(String)
|
||||
is_world_extend: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
|
||||
plus_character: Mapped[Optional[int]] = mapped_column(Integer)
|
||||
|
||||
append_parent_id: Mapped[Optional[str]] = mapped_column(
|
||||
ForeignKey("pack.id", onupdate="CASCADE", ondelete="CASCADE")
|
||||
)
|
||||
|
||||
parent: Mapped["Pack"] = relationship(
|
||||
"Pack",
|
||||
back_populates="appendages",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
remote_side=[id],
|
||||
)
|
||||
appendages: Mapped[list["Pack"]] = relationship("Pack", back_populates="parent")
|
||||
|
||||
|
||||
class PackLocalization(ModelBase, ReprHelper):
|
||||
__tablename__ = "pack_localization"
|
||||
|
||||
pack: Mapped["Pack"] = relationship(back_populates="localized_entries")
|
||||
id: Mapped[str] = mapped_column(
|
||||
ForeignKey("pack.id", onupdate="CASCADE", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
lang: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column(String)
|
||||
description: Mapped[Optional[str]] = mapped_column(Text)
|
192
src/arcaea_offline/database/models/play_result.py
Normal file
192
src/arcaea_offline/database/models/play_result.py
Normal file
@ -0,0 +1,192 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from sqlalchemy import Integer, String, Text, Uuid, case, func, inspect, select, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy_utils import create_view
|
||||
|
||||
from ._base import ModelBase, ModelViewBase, ReprHelper
|
||||
from .chart_info import ChartInfo
|
||||
from .difficulty import Difficulty
|
||||
|
||||
__all__ = [
|
||||
"CalculatedPotential",
|
||||
"PlayResult",
|
||||
"PlayResultBest",
|
||||
"PlayResultCalculated",
|
||||
]
|
||||
|
||||
|
||||
class PlayResult(ModelBase, ReprHelper):
|
||||
__tablename__ = "play_result"
|
||||
|
||||
id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)
|
||||
uuid: Mapped[UUID] = mapped_column(
|
||||
Uuid, nullable=False, unique=True, default=lambda: uuid4()
|
||||
)
|
||||
song_id: Mapped[str] = mapped_column(String)
|
||||
rating_class: Mapped[int] = mapped_column(Integer)
|
||||
played_at: Mapped[Optional[datetime]] = mapped_column(
|
||||
default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
pure_early: Mapped[Optional[int]]
|
||||
pure_late: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
far_early: Mapped[Optional[int]]
|
||||
far_late: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
|
||||
max_recall: Mapped[Optional[int]]
|
||||
clear_type: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]]
|
||||
comment: Mapped[Optional[str]] = mapped_column(Text)
|
||||
|
||||
|
||||
class PlayResultCalculated(ModelViewBase, ReprHelper):
|
||||
__tablename__ = "play_results_calculated"
|
||||
|
||||
id: Mapped[int]
|
||||
uuid: Mapped[UUID]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
pure_early: Mapped[Optional[int]]
|
||||
pure_late: Mapped[Optional[int]]
|
||||
shiny_pure: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
far_early: Mapped[Optional[int]]
|
||||
far_late: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
played_at: Mapped[Optional[datetime]]
|
||||
max_recall: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]]
|
||||
clear_type: Mapped[Optional[int]]
|
||||
potential: Mapped[float]
|
||||
comment: Mapped[Optional[str]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
PlayResult.id,
|
||||
Difficulty.song_id,
|
||||
Difficulty.rating_class,
|
||||
PlayResult.score,
|
||||
PlayResult.pure,
|
||||
(
|
||||
case(
|
||||
(
|
||||
(
|
||||
ChartInfo.notes.is_not(None)
|
||||
& PlayResult.pure.is_not(None)
|
||||
& PlayResult.far.is_not(None)
|
||||
& (ChartInfo.notes != 0)
|
||||
),
|
||||
PlayResult.score
|
||||
- func.floor(
|
||||
(PlayResult.pure * 10000000.0 / ChartInfo.notes)
|
||||
+ (PlayResult.far * 0.5 * 10000000.0 / ChartInfo.notes)
|
||||
),
|
||||
),
|
||||
else_=text("NULL"),
|
||||
)
|
||||
).label("shiny_pure"),
|
||||
PlayResult.far,
|
||||
PlayResult.lost,
|
||||
PlayResult.played_at,
|
||||
PlayResult.max_recall,
|
||||
PlayResult.modifier,
|
||||
PlayResult.clear_type,
|
||||
case(
|
||||
(PlayResult.score >= 10000000, ChartInfo.constant / 10.0 + 2), # noqa: PLR2004
|
||||
(
|
||||
PlayResult.score >= 9800000, # noqa: PLR2004
|
||||
ChartInfo.constant / 10.0
|
||||
+ 1
|
||||
+ (PlayResult.score - 9800000) / 200000.0,
|
||||
),
|
||||
else_=func.max(
|
||||
(ChartInfo.constant / 10.0)
|
||||
+ (PlayResult.score - 9500000) / 300000.0,
|
||||
0,
|
||||
),
|
||||
).label("potential"),
|
||||
PlayResult.comment,
|
||||
)
|
||||
.select_from(Difficulty)
|
||||
.join(
|
||||
ChartInfo,
|
||||
(Difficulty.song_id == ChartInfo.song_id)
|
||||
& (Difficulty.rating_class == ChartInfo.rating_class),
|
||||
)
|
||||
.join(
|
||||
PlayResult,
|
||||
(Difficulty.song_id == PlayResult.song_id)
|
||||
& (Difficulty.rating_class == PlayResult.rating_class),
|
||||
),
|
||||
metadata=ModelViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
||||
|
||||
|
||||
class PlayResultBest(ModelViewBase, ReprHelper):
|
||||
__tablename__ = "play_results_best"
|
||||
|
||||
id: Mapped[int]
|
||||
uuid: Mapped[UUID]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
pure_early: Mapped[Optional[int]]
|
||||
pure_late: Mapped[Optional[int]]
|
||||
shiny_pure: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
far_early: Mapped[Optional[int]]
|
||||
far_late: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
played_at: Mapped[Optional[datetime]]
|
||||
max_recall: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]]
|
||||
clear_type: Mapped[Optional[int]]
|
||||
potential: Mapped[float]
|
||||
comment: Mapped[Optional[str]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
*[
|
||||
col
|
||||
for col in inspect(PlayResultCalculated).columns
|
||||
if col.name != "potential"
|
||||
],
|
||||
func.max(PlayResultCalculated.potential).label("potential"),
|
||||
)
|
||||
.select_from(PlayResultCalculated)
|
||||
.group_by(PlayResultCalculated.song_id, PlayResultCalculated.rating_class)
|
||||
.order_by(PlayResultCalculated.potential.desc()),
|
||||
metadata=ModelViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
||||
|
||||
|
||||
class CalculatedPotential(ModelViewBase, ReprHelper):
|
||||
__tablename__ = "calculated_potential"
|
||||
|
||||
b30: Mapped[float]
|
||||
|
||||
_select_bests_subquery = (
|
||||
select(PlayResultBest.potential.label("b30_sum"))
|
||||
.order_by(PlayResultBest.potential.desc())
|
||||
.limit(30)
|
||||
.subquery()
|
||||
)
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(func.avg(_select_bests_subquery.c.b30_sum).label("b30")),
|
||||
metadata=ModelViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
85
src/arcaea_offline/database/models/song.py
Normal file
85
src/arcaea_offline/database/models/song.py
Normal file
@ -0,0 +1,85 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, Integer, Numeric, String, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from ._base import ModelBase, ReprHelper
|
||||
from ._types import ForceTimezoneDateTime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .difficulty import Difficulty
|
||||
from .pack import Pack
|
||||
|
||||
|
||||
class Song(ModelBase, ReprHelper):
|
||||
__tablename__ = "song"
|
||||
|
||||
pack_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("pack.id", onupdate="CASCADE", ondelete="CASCADE")
|
||||
)
|
||||
pack: Mapped["Pack"] = relationship(back_populates="songs")
|
||||
difficulties: Mapped[list["Difficulty"]] = relationship(
|
||||
back_populates="song",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
localized_entries: Mapped[list["SongLocalization"]] = relationship(
|
||||
back_populates="song",
|
||||
cascade="all, delete",
|
||||
passive_deletes=True,
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
idx: Mapped[Optional[int]] = mapped_column(Integer)
|
||||
title: Mapped[Optional[str]] = mapped_column(String, index=True)
|
||||
artist: Mapped[Optional[str]] = mapped_column(String, index=True)
|
||||
is_deleted: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
|
||||
added_at: Mapped[datetime] = mapped_column(
|
||||
ForceTimezoneDateTime, nullable=False, index=True
|
||||
)
|
||||
version: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
bpm: Mapped[Optional[str]] = mapped_column(String)
|
||||
bpm_base: Mapped[Optional[Decimal]] = mapped_column(Numeric(asdecimal=True))
|
||||
is_remote: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
is_unlockable_in_world: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
is_beyond_unlock_state_local: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
||||
purchase: Mapped[Optional[str]] = mapped_column(String)
|
||||
category: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
side: Mapped[Optional[int]] = mapped_column(Integer)
|
||||
bg: Mapped[Optional[str]] = mapped_column(String)
|
||||
bg_inverse: Mapped[Optional[str]] = mapped_column(String)
|
||||
bg_day: Mapped[Optional[str]] = mapped_column(String)
|
||||
bg_night: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
source: Mapped[Optional[str]] = mapped_column(String)
|
||||
source_copyright: Mapped[Optional[str]] = mapped_column(String)
|
||||
|
||||
|
||||
class SongLocalization(ModelBase, ReprHelper):
|
||||
__tablename__ = "song_localization"
|
||||
|
||||
song: Mapped["Song"] = relationship(back_populates="localized_entries")
|
||||
id: Mapped[str] = mapped_column(
|
||||
ForeignKey("song.id", onupdate="CASCADE", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
lang: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
title: Mapped[Optional[str]] = mapped_column(String)
|
||||
source: Mapped[Optional[str]] = mapped_column(String)
|
||||
has_jacket: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, insert_default=False, server_default=text("0")
|
||||
)
|
@ -1 +0,0 @@
|
||||
from .api_data import AndrealImageGeneratorApiDataConverter
|
14
src/arcaea_offline/external/andreal/account.py
vendored
14
src/arcaea_offline/external/andreal/account.py
vendored
@ -1,14 +0,0 @@
|
||||
class AndrealImageGeneratorAccount:
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Player",
|
||||
code: int = 123456789,
|
||||
rating: int = -1,
|
||||
character: int = 5,
|
||||
character_uncapped: bool = False,
|
||||
):
|
||||
self.name = name
|
||||
self.code = code
|
||||
self.rating = rating
|
||||
self.character = character
|
||||
self.character_uncapped = character_uncapped
|
94
src/arcaea_offline/external/andreal/api_data.py
vendored
94
src/arcaea_offline/external/andreal/api_data.py
vendored
@ -1,94 +0,0 @@
|
||||
from typing import Optional, Union
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...models import CalculatedPotential, ScoreBest, ScoreCalculated
|
||||
from .account import AndrealImageGeneratorAccount
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataConverter:
|
||||
def __init__(
|
||||
self,
|
||||
session: Session,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
):
|
||||
self.session = session
|
||||
self.account = account
|
||||
|
||||
def account_info(self):
|
||||
return {
|
||||
"code": self.account.code,
|
||||
"name": self.account.name,
|
||||
"is_char_uncapped": self.account.character_uncapped,
|
||||
"rating": self.account.rating,
|
||||
"character": self.account.character,
|
||||
}
|
||||
|
||||
def score(self, score: Union[ScoreCalculated, ScoreBest]):
|
||||
return {
|
||||
"score": score.score,
|
||||
"health": 75,
|
||||
"rating": score.potential,
|
||||
"song_id": score.song_id,
|
||||
"modifier": score.modifier or 0,
|
||||
"difficulty": score.rating_class,
|
||||
"clear_type": score.clear_type or 1,
|
||||
"best_clear_type": score.clear_type or 1,
|
||||
"time_played": score.date * 1000 if score.date else 0,
|
||||
"near_count": score.far,
|
||||
"miss_count": score.lost,
|
||||
"perfect_count": score.pure,
|
||||
"shiny_perfect_count": score.shiny_pure,
|
||||
}
|
||||
|
||||
def user_info(self, score: Optional[ScoreCalculated] = None):
|
||||
if not score:
|
||||
score = self.session.scalar(
|
||||
select(ScoreCalculated).order_by(ScoreCalculated.date.desc()).limit(1)
|
||||
)
|
||||
if not score:
|
||||
raise ValueError("No score available.")
|
||||
|
||||
return {
|
||||
"content": {
|
||||
"account_info": self.account_info(),
|
||||
"recent_score": [self.score(score)],
|
||||
}
|
||||
}
|
||||
|
||||
def user_best(self, song_id: str, rating_class: int):
|
||||
score = self.session.scalar(
|
||||
select(ScoreBest).where(
|
||||
(ScoreBest.song_id == song_id)
|
||||
& (ScoreBest.rating_class == rating_class)
|
||||
)
|
||||
)
|
||||
if not score:
|
||||
raise ValueError("No score available.")
|
||||
|
||||
return {
|
||||
"content": {
|
||||
"account_info": self.account_info(),
|
||||
"record": self.score(score),
|
||||
}
|
||||
}
|
||||
|
||||
def user_best30(self):
|
||||
scores = list(
|
||||
self.session.scalars(
|
||||
select(ScoreBest).order_by(ScoreBest.potential.desc()).limit(40)
|
||||
)
|
||||
)
|
||||
if not scores:
|
||||
raise ValueError("No score available.")
|
||||
best30_avg = self.session.scalar(select(CalculatedPotential.b30))
|
||||
|
||||
return {
|
||||
"content": {
|
||||
"account_info": self.account_info(),
|
||||
"best30_avg": best30_avg,
|
||||
"best30_list": [self.score(score) for score in scores[:30]],
|
||||
"best30_overflow": [self.score(score) for score in scores[-10:]],
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
from .packlist import PacklistParser
|
||||
from .songlist import SonglistDifficultiesParser, SonglistParser
|
||||
from .st3 import St3ScoreParser
|
72
src/arcaea_offline/external/arcaea/common.py
vendored
72
src/arcaea_offline/external/arcaea/common.py
vendored
@ -1,72 +0,0 @@
|
||||
import contextlib
|
||||
import json
|
||||
from os import PathLike
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
from sqlalchemy.orm import DeclarativeBase, Session
|
||||
|
||||
|
||||
def to_db_value(val: Any) -> Any:
|
||||
if not val:
|
||||
return None
|
||||
elif isinstance(val, list):
|
||||
return json.dumps(val, ensure_ascii=False)
|
||||
else:
|
||||
return val
|
||||
|
||||
|
||||
def is_localized(item: dict, key: str, append_localized: bool = True):
|
||||
item_key = f"{key}_localized" if append_localized else key
|
||||
subitem: Optional[dict] = item.get(item_key)
|
||||
return subitem and (
|
||||
subitem.get("ja")
|
||||
or subitem.get("ko")
|
||||
or subitem.get("zh-Hant")
|
||||
or subitem.get("zh-Hans")
|
||||
)
|
||||
|
||||
|
||||
def set_model_localized_attrs(
|
||||
model: DeclarativeBase, item: dict, model_key: str, item_key: Optional[str] = None
|
||||
):
|
||||
if item_key is None:
|
||||
item_key = f"{model_key}_localized"
|
||||
subitem: dict = item.get(item_key, {})
|
||||
if not subitem:
|
||||
return
|
||||
setattr(model, f"{model_key}_ja", to_db_value(subitem.get("ja")))
|
||||
setattr(model, f"{model_key}_ko", to_db_value(subitem.get("ko")))
|
||||
setattr(model, f"{model_key}_zh_hans", to_db_value(subitem.get("zh-Hans")))
|
||||
setattr(model, f"{model_key}_zh_hant", to_db_value(subitem.get("zh-Hant")))
|
||||
|
||||
|
||||
class ArcaeaParser:
|
||||
def __init__(self, filepath: Union[str, bytes, PathLike]):
|
||||
self.filepath = filepath
|
||||
|
||||
def read_file_text(self):
|
||||
file_handle = None
|
||||
|
||||
with contextlib.suppress(TypeError):
|
||||
# original open
|
||||
file_handle = open(self.filepath, "r", encoding="utf-8")
|
||||
|
||||
if file_handle is None:
|
||||
try:
|
||||
# or maybe a `pathlib.Path` subset
|
||||
# or an `importlib.resources.abc.Traversable` like object
|
||||
# e.g. `zipfile.Path`
|
||||
file_handle = self.filepath.open(mode="r", encoding="utf-8")
|
||||
except Exception as e:
|
||||
raise ValueError("Invalid `filepath`.") from e
|
||||
|
||||
with file_handle:
|
||||
return file_handle.read()
|
||||
|
||||
def parse(self) -> List[DeclarativeBase]:
|
||||
...
|
||||
|
||||
def write_database(self, session: Session):
|
||||
results = self.parse()
|
||||
for result in results:
|
||||
session.merge(result)
|
32
src/arcaea_offline/external/arcaea/packlist.py
vendored
32
src/arcaea_offline/external/arcaea/packlist.py
vendored
@ -1,32 +0,0 @@
|
||||
import json
|
||||
from typing import List, Union
|
||||
|
||||
from ...models.songs import Pack, PackLocalized
|
||||
from .common import ArcaeaParser, is_localized, set_model_localized_attrs
|
||||
|
||||
|
||||
class PacklistParser(ArcaeaParser):
|
||||
def __init__(self, filepath):
|
||||
super().__init__(filepath)
|
||||
|
||||
def parse(self) -> List[Union[Pack, PackLocalized]]:
|
||||
packlist_json_root = json.loads(self.read_file_text())
|
||||
|
||||
packlist_json = packlist_json_root["packs"]
|
||||
results: List[Union[Pack, PackLocalized]] = [
|
||||
Pack(id="single", name="Memory Archive")
|
||||
]
|
||||
for item in packlist_json:
|
||||
pack = Pack()
|
||||
pack.id = item["id"]
|
||||
pack.name = item["name_localized"]["en"]
|
||||
pack.description = item["description_localized"]["en"] or None
|
||||
results.append(pack)
|
||||
|
||||
if is_localized(item, "name") or is_localized(item, "description"):
|
||||
pack_localized = PackLocalized(id=pack.id)
|
||||
set_model_localized_attrs(pack_localized, item, "name")
|
||||
set_model_localized_attrs(pack_localized, item, "description")
|
||||
results.append(pack_localized)
|
||||
|
||||
return results
|
107
src/arcaea_offline/external/arcaea/songlist.py
vendored
107
src/arcaea_offline/external/arcaea/songlist.py
vendored
@ -1,107 +0,0 @@
|
||||
import json
|
||||
from typing import List, Union
|
||||
|
||||
from ...models.songs import Difficulty, DifficultyLocalized, Song, SongLocalized
|
||||
from .common import ArcaeaParser, is_localized, set_model_localized_attrs, to_db_value
|
||||
|
||||
|
||||
class SonglistParser(ArcaeaParser):
|
||||
def __init__(self, filepath):
|
||||
super().__init__(filepath)
|
||||
|
||||
def parse(
|
||||
self,
|
||||
) -> List[Union[Song, SongLocalized, Difficulty, DifficultyLocalized]]:
|
||||
songlist_json_root = json.loads(self.read_file_text())
|
||||
|
||||
songlist_json = songlist_json_root["songs"]
|
||||
results = []
|
||||
for item in songlist_json:
|
||||
song = Song()
|
||||
song.idx = item["idx"]
|
||||
song.id = item["id"]
|
||||
song.title = item["title_localized"]["en"]
|
||||
song.artist = item["artist"]
|
||||
song.bpm = item["bpm"]
|
||||
song.bpm_base = item["bpm_base"]
|
||||
song.set = item["set"]
|
||||
song.audio_preview = item["audioPreview"]
|
||||
song.audio_preview_end = item["audioPreviewEnd"]
|
||||
song.side = item["side"]
|
||||
song.version = item["version"]
|
||||
song.date = item["date"]
|
||||
song.bg = to_db_value(item.get("bg"))
|
||||
song.bg_inverse = to_db_value(item.get("bg_inverse"))
|
||||
if item.get("bg_daynight"):
|
||||
song.bg_day = to_db_value(item["bg_daynight"].get("day"))
|
||||
song.bg_night = to_db_value(item["bg_daynight"].get("night"))
|
||||
if item.get("source_localized"):
|
||||
song.source = item["source_localized"]["en"]
|
||||
song.source_copyright = to_db_value(item.get("source_copyright"))
|
||||
results.append(song)
|
||||
|
||||
if (
|
||||
is_localized(item, "title")
|
||||
or is_localized(item, "search_title", append_localized=False)
|
||||
or is_localized(item, "search_artist", append_localized=False)
|
||||
or is_localized(item, "source")
|
||||
):
|
||||
song_localized = SongLocalized(id=song.id)
|
||||
set_model_localized_attrs(song_localized, item, "title")
|
||||
set_model_localized_attrs(
|
||||
song_localized, item, "search_title", "search_title"
|
||||
)
|
||||
set_model_localized_attrs(
|
||||
song_localized, item, "search_artist", "search_artist"
|
||||
)
|
||||
set_model_localized_attrs(song_localized, item, "source")
|
||||
results.append(song_localized)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
class SonglistDifficultiesParser(ArcaeaParser):
|
||||
def __init__(self, filepath):
|
||||
self.filepath = filepath
|
||||
|
||||
def parse(self) -> List[Union[Difficulty, DifficultyLocalized]]:
|
||||
songlist_json_root = json.loads(self.read_file_text())
|
||||
|
||||
songlist_json = songlist_json_root["songs"]
|
||||
results = []
|
||||
for song_item in songlist_json:
|
||||
if not song_item.get("difficulties"):
|
||||
continue
|
||||
|
||||
for item in song_item["difficulties"]:
|
||||
if item["rating"] == 0:
|
||||
continue
|
||||
|
||||
chart = Difficulty(song_id=song_item["id"])
|
||||
chart.rating_class = item["ratingClass"]
|
||||
chart.rating = item["rating"]
|
||||
chart.rating_plus = item.get("ratingPlus") or False
|
||||
chart.chart_designer = item["chartDesigner"]
|
||||
chart.jacket_desginer = item.get("jacketDesigner") or None
|
||||
chart.audio_override = item.get("audioOverride") or False
|
||||
chart.jacket_override = item.get("jacketOverride") or False
|
||||
chart.jacket_night = item.get("jacketNight") or None
|
||||
chart.title = item.get("title_localized", {}).get("en") or None
|
||||
chart.artist = item.get("artist") or None
|
||||
chart.bg = item.get("bg") or None
|
||||
chart.bg_inverse = item.get("bg_inverse")
|
||||
chart.bpm = item.get("bpm") or None
|
||||
chart.bpm_base = item.get("bpm_base") or None
|
||||
chart.version = item.get("version") or None
|
||||
chart.date = item.get("date") or None
|
||||
results.append(chart)
|
||||
|
||||
if is_localized(item, "title") or is_localized(item, "artist"):
|
||||
chart_localized = DifficultyLocalized(
|
||||
song_id=chart.song_id, rating_class=chart.rating_class
|
||||
)
|
||||
set_model_localized_attrs(chart_localized, item, "title")
|
||||
set_model_localized_attrs(chart_localized, item, "artist")
|
||||
results.append(chart_localized)
|
||||
|
||||
return results
|
77
src/arcaea_offline/external/arcaea/st3.py
vendored
77
src/arcaea_offline/external/arcaea/st3.py
vendored
@ -1,77 +0,0 @@
|
||||
import logging
|
||||
import sqlite3
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...models.scores import Score
|
||||
from .common import ArcaeaParser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class St3ScoreParser(ArcaeaParser):
|
||||
def __init__(self, filepath):
|
||||
super().__init__(filepath)
|
||||
|
||||
def parse(self) -> List[Score]:
|
||||
items = []
|
||||
with sqlite3.connect(self.filepath) as st3_conn:
|
||||
cursor = st3_conn.cursor()
|
||||
db_scores = cursor.execute(
|
||||
"SELECT songId, songDifficulty, score, perfectCount, nearCount, missCount, date, modifier FROM scores"
|
||||
).fetchall()
|
||||
for (
|
||||
song_id,
|
||||
rating_class,
|
||||
score,
|
||||
pure,
|
||||
far,
|
||||
lost,
|
||||
date,
|
||||
modifier,
|
||||
) in db_scores:
|
||||
clear_type = cursor.execute(
|
||||
"SELECT clearType FROM cleartypes WHERE songId = ? AND songDifficulty = ?",
|
||||
(song_id, rating_class),
|
||||
).fetchone()[0]
|
||||
|
||||
date_str = str(date)
|
||||
date = None if len(date_str) < 7 else int(date_str.ljust(10, "0"))
|
||||
|
||||
items.append(
|
||||
Score(
|
||||
song_id=song_id,
|
||||
rating_class=rating_class,
|
||||
score=score,
|
||||
pure=pure,
|
||||
far=far,
|
||||
lost=lost,
|
||||
date=date,
|
||||
modifier=modifier,
|
||||
clear_type=clear_type,
|
||||
comment="Imported from st3",
|
||||
)
|
||||
)
|
||||
|
||||
return items
|
||||
|
||||
def write_database(self, session: Session, *, skip_duplicate=True):
|
||||
parsed_scores = self.parse()
|
||||
for parsed_score in parsed_scores:
|
||||
query_score = session.scalar(
|
||||
select(Score).where(
|
||||
(Score.song_id == parsed_score.song_id)
|
||||
& (Score.rating_class == parsed_score.rating_class)
|
||||
& (Score.score == parsed_score.score)
|
||||
)
|
||||
)
|
||||
|
||||
if query_score and skip_duplicate:
|
||||
logger.info(
|
||||
f"{repr(parsed_score)} skipped because "
|
||||
f"potential duplicate item {repr(query_score)} found."
|
||||
)
|
||||
continue
|
||||
session.add(parsed_score)
|
@ -1 +0,0 @@
|
||||
from .arcsong_db import ArcsongDbParser
|
@ -1,34 +0,0 @@
|
||||
import sqlite3
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...models.songs import ChartInfo
|
||||
|
||||
|
||||
class ArcsongDbParser:
|
||||
def __init__(self, filepath):
|
||||
self.filepath = filepath
|
||||
|
||||
def parse(self) -> List[ChartInfo]:
|
||||
results = []
|
||||
with sqlite3.connect(self.filepath) as conn:
|
||||
cursor = conn.cursor()
|
||||
arcsong_db_results = cursor.execute(
|
||||
"SELECT song_id, rating_class, rating, note FROM charts"
|
||||
)
|
||||
for result in arcsong_db_results:
|
||||
chart = ChartInfo(
|
||||
song_id=result[0],
|
||||
rating_class=result[1],
|
||||
constant=result[2],
|
||||
notes=result[3] or None,
|
||||
)
|
||||
results.append(chart)
|
||||
|
||||
return results
|
||||
|
||||
def write_database(self, session: Session):
|
||||
results = self.parse()
|
||||
for result in results:
|
||||
session.merge(result)
|
155
src/arcaea_offline/external/arcsong/arcsong_json.py
vendored
155
src/arcaea_offline/external/arcsong/arcsong_json.py
vendored
@ -1,155 +0,0 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import List, Optional, TypedDict
|
||||
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...models import (
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
DifficultyLocalized,
|
||||
Pack,
|
||||
Song,
|
||||
SongLocalized,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TArcSongJsonDifficultyItem(TypedDict):
|
||||
name_en: str
|
||||
name_jp: str
|
||||
artist: str
|
||||
bpm: str
|
||||
bpm_base: float
|
||||
set: str
|
||||
set_friendly: str
|
||||
time: int
|
||||
side: int
|
||||
world_unlock: bool
|
||||
remote_download: bool
|
||||
bg: str
|
||||
date: int
|
||||
version: str
|
||||
difficulty: int
|
||||
rating: int
|
||||
note: int
|
||||
chart_designer: str
|
||||
jacket_designer: str
|
||||
jacket_override: bool
|
||||
audio_override: bool
|
||||
|
||||
|
||||
class TArcSongJsonSongItem(TypedDict):
|
||||
song_id: str
|
||||
difficulties: List[TArcSongJsonDifficultyItem]
|
||||
alias: List[str]
|
||||
|
||||
|
||||
class TArcSongJson(TypedDict):
|
||||
songs: List[TArcSongJsonSongItem]
|
||||
|
||||
|
||||
class ArcSongJsonBuilder:
|
||||
def __init__(self, session: Session):
|
||||
self.session = session
|
||||
|
||||
def get_difficulty_item(
|
||||
self,
|
||||
difficulty: Difficulty,
|
||||
song: Song,
|
||||
pack: Pack,
|
||||
song_localized: Optional[SongLocalized],
|
||||
) -> TArcSongJsonDifficultyItem:
|
||||
if "_append_" in pack.id:
|
||||
base_pack = self.session.scalar(
|
||||
select(Pack).where(Pack.id == re.sub(r"_append_.*$", "", pack.id))
|
||||
)
|
||||
else:
|
||||
base_pack = None
|
||||
|
||||
difficulty_localized = self.session.scalar(
|
||||
select(DifficultyLocalized).where(
|
||||
(DifficultyLocalized.song_id == difficulty.song_id)
|
||||
& (DifficultyLocalized.rating_class == difficulty.rating_class)
|
||||
)
|
||||
)
|
||||
chart_info = self.session.scalar(
|
||||
select(ChartInfo).where(
|
||||
(ChartInfo.song_id == difficulty.song_id)
|
||||
& (ChartInfo.rating_class == difficulty.rating_class)
|
||||
)
|
||||
)
|
||||
|
||||
if difficulty_localized:
|
||||
name_jp = difficulty_localized.title_ja or ""
|
||||
elif song_localized:
|
||||
name_jp = song_localized.title_ja or ""
|
||||
else:
|
||||
name_jp = ""
|
||||
|
||||
return {
|
||||
"name_en": difficulty.title or song.title,
|
||||
"name_jp": name_jp,
|
||||
"artist": difficulty.artist or song.artist,
|
||||
"bpm": difficulty.bpm or song.bpm or "",
|
||||
"bpm_base": difficulty.bpm_base or song.bpm_base or 0.0,
|
||||
"set": song.set,
|
||||
"set_friendly": f"{base_pack.name} - {pack.name}"
|
||||
if base_pack
|
||||
else pack.name,
|
||||
"time": 0,
|
||||
"side": song.side or 0,
|
||||
"world_unlock": False,
|
||||
"remote_download": False,
|
||||
"bg": difficulty.bg or song.bg or "",
|
||||
"date": difficulty.date or song.date or 0,
|
||||
"version": difficulty.version or song.version or "",
|
||||
"difficulty": difficulty.rating * 2 + int(difficulty.rating_plus),
|
||||
"rating": chart_info.constant or 0 if chart_info else 0,
|
||||
"note": chart_info.notes or 0 if chart_info else 0,
|
||||
"chart_designer": difficulty.chart_designer or "",
|
||||
"jacket_designer": difficulty.jacket_desginer or "",
|
||||
"jacket_override": difficulty.jacket_override,
|
||||
"audio_override": difficulty.audio_override,
|
||||
}
|
||||
|
||||
def get_song_item(self, song: Song) -> TArcSongJsonSongItem:
|
||||
difficulties = self.session.scalars(
|
||||
select(Difficulty).where(Difficulty.song_id == song.id)
|
||||
)
|
||||
|
||||
pack = self.session.scalar(select(Pack).where(Pack.id == song.set))
|
||||
if not pack:
|
||||
logger.warning(f'Cannot find pack "{song.set}", using placeholder instead.')
|
||||
pack = Pack(id="unknown", name="Unknown", description="__PLACEHOLDER__")
|
||||
song_localized = self.session.scalar(
|
||||
select(SongLocalized).where(SongLocalized.id == song.id)
|
||||
)
|
||||
|
||||
return {
|
||||
"song_id": song.id,
|
||||
"difficulties": [
|
||||
self.get_difficulty_item(difficulty, song, pack, song_localized)
|
||||
for difficulty in difficulties
|
||||
],
|
||||
"alias": [],
|
||||
}
|
||||
|
||||
def generate_arcsong_json(self) -> TArcSongJson:
|
||||
songs = self.session.scalars(select(Song))
|
||||
arcsong_songs = []
|
||||
for song in songs:
|
||||
proceed = self.session.scalar(
|
||||
select(func.count(Difficulty.rating_class)).where(
|
||||
Difficulty.song_id == song.id
|
||||
)
|
||||
)
|
||||
|
||||
if not proceed:
|
||||
continue
|
||||
|
||||
arcsong_songs.append(self.get_song_item(song))
|
||||
|
||||
return {"songs": arcsong_songs}
|
3
src/arcaea_offline/external/exporters/andreal/__init__.py
vendored
Normal file
3
src/arcaea_offline/external/exporters/andreal/__init__.py
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
from .api_data import AndrealImageGeneratorApiDataExporter
|
||||
|
||||
__all__ = ["AndrealImageGeneratorApiDataExporter"]
|
172
src/arcaea_offline/external/exporters/andreal/api_data.py
vendored
Normal file
172
src/arcaea_offline/external/exporters/andreal/api_data.py
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
import statistics
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import (
|
||||
PlayResultBest,
|
||||
PlayResultCalculated,
|
||||
)
|
||||
|
||||
from .definitions import (
|
||||
AndrealImageGeneratorApiDataAccountInfo,
|
||||
AndrealImageGeneratorApiDataRoot,
|
||||
AndrealImageGeneratorApiDataScoreItem,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class AndrealImageGeneratorAccount:
|
||||
name: str = "Player"
|
||||
code: int = 123456789
|
||||
rating: int = -1
|
||||
character: int = 5
|
||||
character_uncapped: bool = False
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataExporter:
|
||||
@staticmethod
|
||||
def craft_account_info(
|
||||
account: AndrealImageGeneratorAccount,
|
||||
) -> AndrealImageGeneratorApiDataAccountInfo:
|
||||
return {
|
||||
"code": account.code,
|
||||
"name": account.name,
|
||||
"is_char_uncapped": account.character_uncapped,
|
||||
"rating": account.rating,
|
||||
"character": account.character,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def craft_score_item(
|
||||
play_result: Union[PlayResultCalculated, PlayResultBest],
|
||||
) -> AndrealImageGeneratorApiDataScoreItem:
|
||||
modifier = play_result.modifier.value if play_result.modifier else 0
|
||||
clear_type = play_result.clear_type.value if play_result.clear_type else 0
|
||||
|
||||
return {
|
||||
"score": play_result.score,
|
||||
"health": 75,
|
||||
"rating": play_result.potential,
|
||||
"song_id": play_result.song_id,
|
||||
"modifier": modifier,
|
||||
"difficulty": play_result.rating_class.value,
|
||||
"clear_type": clear_type,
|
||||
"best_clear_type": clear_type,
|
||||
"time_played": int(play_result.date.timestamp() * 1000)
|
||||
if play_result.date
|
||||
else 0,
|
||||
"near_count": play_result.far,
|
||||
"miss_count": play_result.lost,
|
||||
"perfect_count": play_result.pure,
|
||||
"shiny_perfect_count": play_result.shiny_pure,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def user_info(
|
||||
cls,
|
||||
play_result_calculated: PlayResultCalculated,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
) -> AndrealImageGeneratorApiDataRoot:
|
||||
return {
|
||||
"content": {
|
||||
"account_info": cls.craft_account_info(account),
|
||||
"recent_score": [cls.craft_score_item(play_result_calculated)],
|
||||
}
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def user_best(
|
||||
cls,
|
||||
play_result_best: PlayResultBest,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
) -> AndrealImageGeneratorApiDataRoot:
|
||||
return {
|
||||
"content": {
|
||||
"account_info": cls.craft_account_info(account),
|
||||
"record": cls.craft_score_item(play_result_best),
|
||||
}
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def user_best30(
|
||||
cls,
|
||||
play_results_best: List[PlayResultBest],
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
) -> AndrealImageGeneratorApiDataRoot:
|
||||
play_results_best_sorted = sorted(
|
||||
play_results_best, key=lambda it: it.potential, reverse=True
|
||||
)
|
||||
|
||||
best30_list = play_results_best_sorted[:30]
|
||||
best30_overflow = play_results_best_sorted[30:]
|
||||
|
||||
best30_avg = statistics.fmean([it.potential for it in best30_list])
|
||||
|
||||
return {
|
||||
"content": {
|
||||
"account_info": cls.craft_account_info(account),
|
||||
"best30_avg": best30_avg,
|
||||
"best30_list": [cls.craft_score_item(it) for it in best30_list],
|
||||
"best30_overflow": [cls.craft_score_item(it) for it in best30_overflow],
|
||||
}
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def craft_user_info(
|
||||
cls,
|
||||
session: Session,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
) -> Optional[AndrealImageGeneratorApiDataRoot]:
|
||||
play_result_calculated = session.scalar(
|
||||
select(PlayResultCalculated)
|
||||
.order_by(PlayResultCalculated.date.desc())
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
if play_result_calculated is None:
|
||||
return None
|
||||
|
||||
return cls.user_info(play_result_calculated, account)
|
||||
|
||||
@classmethod
|
||||
def craft_user_best(
|
||||
cls,
|
||||
session: Session,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
*,
|
||||
song_id: str,
|
||||
rating_class: ArcaeaRatingClass,
|
||||
):
|
||||
play_result_best = session.scalar(
|
||||
select(PlayResultBest).where(
|
||||
(PlayResultBest.song_id == song_id)
|
||||
& (PlayResultBest.rating_class == rating_class)
|
||||
)
|
||||
)
|
||||
|
||||
if play_result_best is None:
|
||||
return None
|
||||
|
||||
return cls.user_best(play_result_best, account)
|
||||
|
||||
@classmethod
|
||||
def craft(
|
||||
cls,
|
||||
session: Session,
|
||||
account: AndrealImageGeneratorAccount = AndrealImageGeneratorAccount(),
|
||||
*,
|
||||
limit: int = 40,
|
||||
) -> Optional[AndrealImageGeneratorApiDataRoot]:
|
||||
play_results_best = list(
|
||||
session.scalars(
|
||||
select(PlayResultBest)
|
||||
.order_by(PlayResultBest.potential.desc())
|
||||
.limit(limit)
|
||||
).all()
|
||||
)
|
||||
|
||||
return cls.user_best30(play_results_best, account)
|
38
src/arcaea_offline/external/exporters/andreal/definitions.py
vendored
Normal file
38
src/arcaea_offline/external/exporters/andreal/definitions.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
from typing import List, Optional, TypedDict
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataAccountInfo(TypedDict):
|
||||
name: str
|
||||
code: int
|
||||
rating: int
|
||||
character: int
|
||||
is_char_uncapped: bool
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataScoreItem(TypedDict):
|
||||
score: int
|
||||
health: int
|
||||
rating: float
|
||||
song_id: str
|
||||
modifier: int
|
||||
difficulty: int
|
||||
clear_type: int
|
||||
best_clear_type: int
|
||||
time_played: int
|
||||
near_count: Optional[int]
|
||||
miss_count: Optional[int]
|
||||
perfect_count: Optional[int]
|
||||
shiny_perfect_count: Optional[int]
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataContent(TypedDict, total=False):
|
||||
account_info: AndrealImageGeneratorApiDataAccountInfo
|
||||
recent_score: List[AndrealImageGeneratorApiDataScoreItem]
|
||||
record: AndrealImageGeneratorApiDataScoreItem
|
||||
best30_avg: float
|
||||
best30_list: List[AndrealImageGeneratorApiDataScoreItem]
|
||||
best30_overflow: List[AndrealImageGeneratorApiDataScoreItem]
|
||||
|
||||
|
||||
class AndrealImageGeneratorApiDataRoot(TypedDict):
|
||||
content: AndrealImageGeneratorApiDataContent
|
3
src/arcaea_offline/external/exporters/arcsong/__init__.py
vendored
Normal file
3
src/arcaea_offline/external/exporters/arcsong/__init__.py
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
from .json import ArcsongJsonExporter
|
||||
|
||||
__all__ = ["ArcsongJsonExporter"]
|
35
src/arcaea_offline/external/exporters/arcsong/definitions.py
vendored
Normal file
35
src/arcaea_offline/external/exporters/arcsong/definitions.py
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
from typing import List, TypedDict
|
||||
|
||||
|
||||
class ArcsongJsonDifficultyItem(TypedDict):
|
||||
name_en: str
|
||||
name_jp: str
|
||||
artist: str
|
||||
bpm: str
|
||||
bpm_base: float
|
||||
set: str
|
||||
set_friendly: str
|
||||
time: int
|
||||
side: int
|
||||
world_unlock: bool
|
||||
remote_download: bool
|
||||
bg: str
|
||||
date: int
|
||||
version: str
|
||||
difficulty: int
|
||||
rating: int
|
||||
note: int
|
||||
chart_designer: str
|
||||
jacket_designer: str
|
||||
jacket_override: bool
|
||||
audio_override: bool
|
||||
|
||||
|
||||
class ArcsongJsonSongItem(TypedDict):
|
||||
song_id: str
|
||||
difficulties: List[ArcsongJsonDifficultyItem]
|
||||
alias: List[str]
|
||||
|
||||
|
||||
class ArcsongJsonRoot(TypedDict):
|
||||
songs: List[ArcsongJsonSongItem]
|
105
src/arcaea_offline/external/exporters/arcsong/json.py
vendored
Normal file
105
src/arcaea_offline/external/exporters/arcsong/json.py
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaLanguage
|
||||
from arcaea_offline.database.models import Difficulty, Pack, Song
|
||||
|
||||
from .definitions import ArcsongJsonDifficultyItem, ArcsongJsonRoot, ArcsongJsonSongItem
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ArcsongJsonExporter:
|
||||
@staticmethod
|
||||
def craft_difficulty_item(
|
||||
difficulty: Difficulty, *, base_pack: Optional[Pack]
|
||||
) -> ArcsongJsonDifficultyItem:
|
||||
song = difficulty.song
|
||||
pack = song.pack
|
||||
chart_info = difficulty.chart_info
|
||||
|
||||
song_localized_ja = next(
|
||||
(lo for lo in song.localized_objects if lo.lang == ArcaeaLanguage.JA),
|
||||
None,
|
||||
)
|
||||
difficulty_localized_ja = next(
|
||||
(lo for lo in difficulty.localized_objects if lo.lang == ArcaeaLanguage.JA),
|
||||
None,
|
||||
)
|
||||
|
||||
if difficulty_localized_ja:
|
||||
name_jp = difficulty_localized_ja.title or ""
|
||||
elif song_localized_ja:
|
||||
name_jp = song_localized_ja.title or ""
|
||||
else:
|
||||
name_jp = ""
|
||||
|
||||
if difficulty.date is not None:
|
||||
date = int(difficulty.date.timestamp())
|
||||
elif song.date is not None:
|
||||
date = int(song.date.timestamp())
|
||||
else:
|
||||
date = 0
|
||||
|
||||
return {
|
||||
"name_en": difficulty.title or song.title,
|
||||
"name_jp": name_jp,
|
||||
"artist": difficulty.artist or song.artist,
|
||||
"bpm": difficulty.bpm or song.bpm or "",
|
||||
"bpm_base": difficulty.bpm_base or song.bpm_base or 0.0,
|
||||
"set": song.pack_id,
|
||||
"set_friendly": f"{base_pack.name} - {pack.name}"
|
||||
if base_pack
|
||||
else pack.name,
|
||||
"time": 0,
|
||||
"side": song.side or 0,
|
||||
"world_unlock": False,
|
||||
"remote_download": False,
|
||||
"bg": difficulty.bg or song.bg or "",
|
||||
"date": date,
|
||||
"version": difficulty.version or song.version or "",
|
||||
"difficulty": difficulty.rating * 2 + int(difficulty.rating_plus),
|
||||
"rating": chart_info.constant or 0 if chart_info else 0,
|
||||
"note": chart_info.notes or 0 if chart_info else 0,
|
||||
"chart_designer": difficulty.chart_designer or "",
|
||||
"jacket_designer": difficulty.jacket_desginer or "",
|
||||
"jacket_override": difficulty.jacket_override,
|
||||
"audio_override": difficulty.audio_override,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def craft(cls, session: Session) -> ArcsongJsonRoot:
|
||||
songs = session.scalars(select(Song))
|
||||
|
||||
arcsong_songs: List[ArcsongJsonSongItem] = []
|
||||
for song in songs:
|
||||
if len(song.difficulties) == 0:
|
||||
continue
|
||||
|
||||
pack = song.pack
|
||||
if "_append_" in pack.id:
|
||||
base_pack = session.scalar(
|
||||
select(Pack).where(Pack.id == re.sub(r"_append_.*$", "", pack.id))
|
||||
)
|
||||
else:
|
||||
base_pack = None
|
||||
|
||||
arcsong_difficulties = []
|
||||
for difficulty in song.difficulties:
|
||||
arcsong_difficulties.append(
|
||||
cls.craft_difficulty_item(difficulty, base_pack=base_pack)
|
||||
)
|
||||
|
||||
arcsong_songs.append(
|
||||
{
|
||||
"song_id": song.id,
|
||||
"difficulties": arcsong_difficulties,
|
||||
"alias": [],
|
||||
}
|
||||
)
|
||||
|
||||
return {"songs": arcsong_songs}
|
0
src/arcaea_offline/external/exporters/defv2/__init__.py
vendored
Normal file
0
src/arcaea_offline/external/exporters/defv2/__init__.py
vendored
Normal file
30
src/arcaea_offline/external/exporters/defv2/definitions.py
vendored
Normal file
30
src/arcaea_offline/external/exporters/defv2/definitions.py
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
from typing import List, Literal, Optional, TypedDict
|
||||
|
||||
|
||||
class ArcaeaOfflineDEFv2PlayResultItem(TypedDict, total=False):
|
||||
id: Optional[int]
|
||||
songId: str
|
||||
ratingClass: int
|
||||
score: int
|
||||
pure: Optional[int]
|
||||
far: Optional[int]
|
||||
lost: Optional[int]
|
||||
date: Optional[int]
|
||||
maxRecall: Optional[int]
|
||||
modifier: Optional[int]
|
||||
clearType: Optional[int]
|
||||
source: Optional[str]
|
||||
comment: Optional[str]
|
||||
|
||||
|
||||
ArcaeaOfflineDEFv2PlayResultRoot = TypedDict(
|
||||
"ArcaeaOfflineDEFv2PlayResultRoot",
|
||||
{
|
||||
"$schema": Literal[
|
||||
"https://arcaeaoffline.sevive.xyz/schemas/def/v2/score.schema.json"
|
||||
],
|
||||
"type": Literal["score"],
|
||||
"version": Literal[2],
|
||||
"scores": List[ArcaeaOfflineDEFv2PlayResultItem],
|
||||
},
|
||||
)
|
42
src/arcaea_offline/external/exporters/defv2/play_result.py
vendored
Normal file
42
src/arcaea_offline/external/exporters/defv2/play_result.py
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
from typing import List
|
||||
|
||||
from arcaea_offline.database.models import PlayResult
|
||||
|
||||
from .definitions import (
|
||||
ArcaeaOfflineDEFv2PlayResultItem,
|
||||
ArcaeaOfflineDEFv2PlayResultRoot,
|
||||
)
|
||||
|
||||
|
||||
class ArcaeaOfflineDEFv2PlayResultExporter:
|
||||
def export(self, items: List[PlayResult]) -> ArcaeaOfflineDEFv2PlayResultRoot:
|
||||
export_items = []
|
||||
for item in items:
|
||||
export_item: ArcaeaOfflineDEFv2PlayResultItem = {
|
||||
"id": item.id,
|
||||
"songId": item.song_id,
|
||||
"ratingClass": item.rating_class.value,
|
||||
"score": item.score,
|
||||
"pure": item.pure,
|
||||
"far": item.far,
|
||||
"lost": item.lost,
|
||||
"date": int(item.date.timestamp() * 1000) if item.date else 0,
|
||||
"maxRecall": item.max_recall,
|
||||
"modifier": (
|
||||
item.modifier.value if item.modifier is not None else None
|
||||
),
|
||||
"clearType": (
|
||||
item.clear_type.value if item.clear_type is not None else None
|
||||
),
|
||||
"source": "https://arcaeaoffline.sevive.xyz/python",
|
||||
"comment": item.comment,
|
||||
}
|
||||
|
||||
export_items.append(export_item)
|
||||
|
||||
return {
|
||||
"$schema": "https://arcaeaoffline.sevive.xyz/schemas/def/v2/score.schema.json",
|
||||
"type": "score",
|
||||
"version": 2,
|
||||
"scores": export_items,
|
||||
}
|
75
src/arcaea_offline/external/exporters/smartrte.py
vendored
Normal file
75
src/arcaea_offline/external/exporters/smartrte.py
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
from typing import List, Tuple
|
||||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import (
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
PlayResultBest,
|
||||
Song,
|
||||
)
|
||||
from arcaea_offline.utils.formatters.rating_class import RatingClassFormatter
|
||||
|
||||
|
||||
class SmartRteBest30CsvExporter:
|
||||
CSV_ROWS = [
|
||||
"SongName",
|
||||
"SongId",
|
||||
"Difficulty",
|
||||
"Score",
|
||||
"Perfect",
|
||||
"Perfect+",
|
||||
"Far",
|
||||
"Lost",
|
||||
"Constant",
|
||||
"PlayRating",
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def rows(cls, session: Session) -> List:
|
||||
results: List[
|
||||
Tuple[str, str, ArcaeaRatingClass, int, int, int, int, int, float]
|
||||
] = (
|
||||
session.query(
|
||||
func.coalesce(Difficulty.title, Song.title),
|
||||
PlayResultBest.song_id,
|
||||
PlayResultBest.rating_class,
|
||||
PlayResultBest.score,
|
||||
PlayResultBest.pure,
|
||||
PlayResultBest.shiny_pure,
|
||||
PlayResultBest.far,
|
||||
PlayResultBest.lost,
|
||||
ChartInfo.constant,
|
||||
PlayResultBest.potential,
|
||||
)
|
||||
.join(
|
||||
ChartInfo,
|
||||
(ChartInfo.song_id == PlayResultBest.song_id)
|
||||
& (ChartInfo.rating_class == PlayResultBest.rating_class),
|
||||
)
|
||||
.join(Song, (Song.id == PlayResultBest.song_id))
|
||||
.join(
|
||||
Difficulty,
|
||||
(Difficulty.song_id == PlayResultBest.song_id)
|
||||
& (Difficulty.rating_class == PlayResultBest.rating_class),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
csv_rows = []
|
||||
csv_rows.append(cls.CSV_ROWS.copy())
|
||||
for _result in results:
|
||||
result = list(_result)
|
||||
|
||||
# replace the comma in song title because the target project
|
||||
# cannot handle quoted string
|
||||
result[0] = result[0].replace(",", "") # type: ignore
|
||||
result[2] = RatingClassFormatter.name(result[2]) # type: ignore
|
||||
result[-2] = result[-2] / 10 # type: ignore
|
||||
result[-1] = round(result[-1], 5) # type: ignore
|
||||
|
||||
csv_rows.append(result)
|
||||
|
||||
return csv_rows
|
@ -1,2 +0,0 @@
|
||||
from . import exporters
|
||||
from .types import ScoreExport
|
19
src/arcaea_offline/external/exports/exporters.py
vendored
19
src/arcaea_offline/external/exports/exporters.py
vendored
@ -1,19 +0,0 @@
|
||||
from ...models import Score
|
||||
from .types import ScoreExport
|
||||
|
||||
|
||||
def score(score: Score) -> ScoreExport:
|
||||
return {
|
||||
"id": score.id,
|
||||
"song_id": score.song_id,
|
||||
"rating_class": score.rating_class,
|
||||
"score": score.score,
|
||||
"pure": score.pure,
|
||||
"far": score.far,
|
||||
"lost": score.lost,
|
||||
"date": score.date,
|
||||
"max_recall": score.max_recall,
|
||||
"modifier": score.modifier,
|
||||
"clear_type": score.clear_type,
|
||||
"comment": score.comment,
|
||||
}
|
16
src/arcaea_offline/external/exports/types.py
vendored
16
src/arcaea_offline/external/exports/types.py
vendored
@ -1,16 +0,0 @@
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
|
||||
class ScoreExport(TypedDict):
|
||||
id: int
|
||||
song_id: str
|
||||
rating_class: int
|
||||
score: int
|
||||
pure: Optional[int]
|
||||
far: Optional[int]
|
||||
lost: Optional[int]
|
||||
date: Optional[int]
|
||||
max_recall: Optional[int]
|
||||
modifier: Optional[int]
|
||||
clear_type: Optional[int]
|
||||
comment: Optional[str]
|
10
src/arcaea_offline/external/importers/arcaea/__init__.py
vendored
Normal file
10
src/arcaea_offline/external/importers/arcaea/__init__.py
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
from .lists import ArcaeaPacklistParser, ArcaeaSonglistParser
|
||||
from .online import ArcaeaOnlineApiParser
|
||||
from .st3 import ArcaeaSt3Parser
|
||||
|
||||
__all__ = [
|
||||
"ArcaeaPacklistParser",
|
||||
"ArcaeaSonglistParser",
|
||||
"ArcaeaOnlineApiParser",
|
||||
"ArcaeaSt3Parser",
|
||||
]
|
31
src/arcaea_offline/external/importers/arcaea/common.py
vendored
Normal file
31
src/arcaea_offline/external/importers/arcaea/common.py
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
from typing import Union
|
||||
|
||||
|
||||
def fix_timestamp(timestamp: int) -> Union[int, None]:
|
||||
"""
|
||||
Some of the `date` column in st3 are unexpectedly truncated. For example,
|
||||
a `1670283375` may be truncated to `167028`, even a single `1`.
|
||||
|
||||
To properly handle this:
|
||||
|
||||
If `timestamp > 1489017600` (the release date of Arcaea), consider it's ok.
|
||||
|
||||
Otherwise, if the timestamp is 'fixable'
|
||||
(`1489 <= timestamp <= 9999` or `timestamp > 14889`),
|
||||
pad zeros to the end of timestamp.
|
||||
For example, a `1566` will be padded to `1566000000`.
|
||||
|
||||
Otherwise, treat the timestamp as `None`.
|
||||
|
||||
:param timestamp: `date` value
|
||||
"""
|
||||
if timestamp > 1489017600: # noqa: PLR2004
|
||||
return timestamp
|
||||
|
||||
timestamp_fixable = 1489 <= timestamp <= 9999 or timestamp > 14889 # noqa: PLR2004
|
||||
if not timestamp_fixable:
|
||||
return None
|
||||
|
||||
timestamp_str = str(timestamp)
|
||||
timestamp_str = timestamp_str.ljust(10, "0")
|
||||
return int(timestamp_str, 10)
|
180
src/arcaea_offline/external/importers/arcaea/lists.py
vendored
Normal file
180
src/arcaea_offline/external/importers/arcaea/lists.py
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
"""
|
||||
packlist and songlist parsers
|
||||
"""
|
||||
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Union
|
||||
|
||||
from arcaea_offline.constants.enums import (
|
||||
ArcaeaLanguage,
|
||||
ArcaeaRatingClass,
|
||||
ArcaeaSongSide,
|
||||
)
|
||||
from arcaea_offline.database.models import (
|
||||
Difficulty,
|
||||
DifficultyLocalization,
|
||||
Pack,
|
||||
PackLocalization,
|
||||
Song,
|
||||
SongLocalization,
|
||||
)
|
||||
|
||||
|
||||
class ArcaeaListParser:
|
||||
def __init__(self, list_text: str):
|
||||
self.list_text = list_text
|
||||
|
||||
|
||||
class ArcaeaPacklistParser(ArcaeaListParser):
|
||||
def parse(self) -> List[Union[Pack, PackLocalization]]:
|
||||
root = json.loads(self.list_text)
|
||||
|
||||
packs = root["packs"]
|
||||
results: List[Union[Pack, PackLocalization]] = [
|
||||
Pack(id="single", name="Memory Archive")
|
||||
]
|
||||
for item in packs:
|
||||
pack = Pack()
|
||||
pack.id = item["id"]
|
||||
pack.name = item["name_localized"]["en"]
|
||||
pack.description = item["description_localized"]["en"] or None
|
||||
results.append(pack)
|
||||
|
||||
for key in ArcaeaLanguage:
|
||||
name_localized = item["name_localized"].get(key.value, None)
|
||||
description_localized = item["description_localized"].get(
|
||||
key.value, None
|
||||
)
|
||||
|
||||
if name_localized or description_localized:
|
||||
pack_localized = PackLocalization(id=pack.id)
|
||||
pack_localized.lang = key.value
|
||||
pack_localized.name = name_localized
|
||||
pack_localized.description = description_localized
|
||||
results.append(pack_localized)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
class ArcaeaSonglistParser(ArcaeaListParser):
|
||||
def parse_songs(self) -> List[Union[Song, SongLocalization]]:
|
||||
root = json.loads(self.list_text)
|
||||
|
||||
songs = root["songs"]
|
||||
results = []
|
||||
for item in songs:
|
||||
song = Song()
|
||||
song.idx = item["idx"]
|
||||
song.id = item["id"]
|
||||
song.title = item["title_localized"]["en"]
|
||||
song.artist = item["artist"]
|
||||
song.bpm = item["bpm"]
|
||||
song.bpm_base = item["bpm_base"]
|
||||
song.pack_id = item["set"]
|
||||
song.side = ArcaeaSongSide(item["side"])
|
||||
song.version = item["version"]
|
||||
song.added_at = datetime.fromtimestamp(item["date"], tz=timezone.utc)
|
||||
song.bg = item.get("bg")
|
||||
song.bg_inverse = item.get("bg_inverse")
|
||||
if item.get("bg_daynight"):
|
||||
song.bg_day = item["bg_daynight"].get("day")
|
||||
song.bg_night = item["bg_daynight"].get("night")
|
||||
if item.get("source_localized"):
|
||||
song.source = item["source_localized"]["en"]
|
||||
song.source_copyright = item.get("source_copyright")
|
||||
results.append(song)
|
||||
|
||||
for lang in ArcaeaLanguage:
|
||||
# SongLocalized objects
|
||||
title_localized = item["title_localized"].get(lang.value, None)
|
||||
source_localized = item.get("source_localized", {}).get(
|
||||
lang.value, None
|
||||
)
|
||||
|
||||
if title_localized or source_localized:
|
||||
song_localized = SongLocalization(id=song.id)
|
||||
song_localized.lang = lang.value
|
||||
song_localized.title = title_localized
|
||||
song_localized.source = source_localized
|
||||
results.append(song_localized)
|
||||
|
||||
# TODO: SongSearchTitle?
|
||||
# search_titles = item.get("search_title", {}).get(lang.value, None)
|
||||
# if search_titles:
|
||||
# for search_title in search_titles:
|
||||
# song_search_word = SongSearchWord(
|
||||
# id=song.id, lang=lang.value, type=1, value=search_title
|
||||
# )
|
||||
# results.append(song_search_word)
|
||||
|
||||
# search_artists = item.get("search_artist", {}).get(lang.value, None)
|
||||
# if search_artists:
|
||||
# for search_artist in search_artists:
|
||||
# song_search_word = SongSearchWord(
|
||||
# id=song.id, lang=lang.value, type=2, value=search_artist
|
||||
# )
|
||||
# results.append(song_search_word)
|
||||
|
||||
return results
|
||||
|
||||
def parse_difficulties(self) -> List[Union[Difficulty, DifficultyLocalization]]:
|
||||
root = json.loads(self.list_text)
|
||||
|
||||
songs = root["songs"]
|
||||
results = []
|
||||
for song in songs:
|
||||
difficulties = song.get("difficulties")
|
||||
if not difficulties:
|
||||
continue
|
||||
|
||||
for item in difficulties:
|
||||
if item["rating"] == 0:
|
||||
continue
|
||||
|
||||
difficulty = Difficulty()
|
||||
difficulty.song_id = song["id"]
|
||||
difficulty.rating_class = ArcaeaRatingClass(item["ratingClass"])
|
||||
difficulty.rating = item["rating"]
|
||||
difficulty.is_rating_plus = item.get("ratingPlus") or False
|
||||
difficulty.chart_designer = item["chartDesigner"]
|
||||
difficulty.jacket_designer = item.get("jacketDesigner") or None
|
||||
difficulty.has_overriding_audio = item.get("audioOverride") or False
|
||||
difficulty.has_overriding_jacket = item.get("jacketOverride") or False
|
||||
difficulty.jacket_night = item.get("jacketNight") or None
|
||||
difficulty.title = item.get("title_localized", {}).get("en") or None
|
||||
difficulty.artist = item.get("artist") or None
|
||||
difficulty.bg = item.get("bg") or None
|
||||
difficulty.bg_inverse = item.get("bg_inverse")
|
||||
difficulty.bpm = item.get("bpm") or None
|
||||
difficulty.bpm_base = item.get("bpm_base") or None
|
||||
difficulty.version = item.get("version") or None
|
||||
difficulty.added_at = (
|
||||
datetime.fromtimestamp(item["date"], tz=timezone.utc)
|
||||
if item.get("date") is not None
|
||||
else None
|
||||
)
|
||||
results.append(difficulty)
|
||||
|
||||
for lang in ArcaeaLanguage:
|
||||
title_localized = item.get("title_localized", {}).get(
|
||||
lang.value, None
|
||||
)
|
||||
artist_localized = item.get("artist_localized", {}).get(
|
||||
lang.value, None
|
||||
)
|
||||
|
||||
if title_localized or artist_localized:
|
||||
difficulty_localized = DifficultyLocalization(
|
||||
song_id=difficulty.song_id,
|
||||
rating_class=difficulty.rating_class,
|
||||
)
|
||||
difficulty_localized.lang = lang.value
|
||||
difficulty_localized.title = title_localized
|
||||
difficulty_localized.artist = artist_localized
|
||||
results.append(difficulty_localized)
|
||||
|
||||
return results
|
||||
|
||||
def parse_all(self):
|
||||
return self.parse_songs() + self.parse_difficulties()
|
97
src/arcaea_offline/external/importers/arcaea/online.py
vendored
Normal file
97
src/arcaea_offline/external/importers/arcaea/online.py
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, List, Literal, Optional, TypedDict
|
||||
|
||||
from arcaea_offline.constants.enums import (
|
||||
ArcaeaPlayResultClearType,
|
||||
ArcaeaPlayResultModifier,
|
||||
ArcaeaRatingClass,
|
||||
)
|
||||
from arcaea_offline.database.models import PlayResult
|
||||
|
||||
from .common import fix_timestamp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class _RatingMePlayResultItem(TypedDict):
|
||||
song_id: str
|
||||
difficulty: int
|
||||
modifier: int
|
||||
rating: float
|
||||
score: int
|
||||
perfect_count: int
|
||||
near_count: int
|
||||
miss_count: int
|
||||
clear_type: int
|
||||
title: Dict[Literal["ja", "en"], str]
|
||||
artist: str
|
||||
time_played: int
|
||||
bg: str
|
||||
|
||||
|
||||
class _RatingMeValue(TypedDict):
|
||||
best_rated_scores: List[_RatingMePlayResultItem]
|
||||
recent_rated_scores: List[_RatingMePlayResultItem]
|
||||
|
||||
|
||||
class _RatingMeResponse(TypedDict):
|
||||
success: bool
|
||||
error_code: Optional[int]
|
||||
value: Optional[_RatingMeValue]
|
||||
|
||||
|
||||
class ArcaeaOnlineApiParser:
|
||||
def __init__(self, api_result_text: str):
|
||||
self.api_result_text = api_result_text
|
||||
self.api_result: _RatingMeResponse = json.loads(api_result_text)
|
||||
|
||||
def parse(self) -> List[PlayResult]:
|
||||
api_result_value = self.api_result.get("value")
|
||||
if not api_result_value:
|
||||
error_code = self.api_result.get("error_code")
|
||||
raise ValueError(
|
||||
f"Cannot parse Arcaea Online API result, error code {error_code}"
|
||||
)
|
||||
|
||||
best30_items = api_result_value.get("best_rated_scores", [])
|
||||
recent_items = api_result_value.get("recent_rated_scores", [])
|
||||
items = best30_items + recent_items
|
||||
|
||||
date_text = (
|
||||
datetime.now(tz=timezone.utc).astimezone().isoformat(timespec="seconds")
|
||||
)
|
||||
|
||||
results: List[PlayResult] = []
|
||||
results_time_played = []
|
||||
for item in items:
|
||||
date_millis = fix_timestamp(item["time_played"])
|
||||
|
||||
if date_millis in results_time_played:
|
||||
# filter out duplicate play results
|
||||
continue
|
||||
|
||||
if date_millis:
|
||||
date = datetime.fromtimestamp(date_millis / 1000).astimezone()
|
||||
results_time_played.append(date_millis)
|
||||
else:
|
||||
date = None
|
||||
|
||||
play_result = PlayResult()
|
||||
play_result.song_id = item["song_id"]
|
||||
play_result.rating_class = ArcaeaRatingClass(item["difficulty"])
|
||||
play_result.score = item["score"]
|
||||
play_result.pure = item["perfect_count"]
|
||||
play_result.far = item["near_count"]
|
||||
play_result.lost = item["miss_count"]
|
||||
play_result.played_at = date
|
||||
play_result.modifier = ArcaeaPlayResultModifier(item["modifier"])
|
||||
play_result.clear_type = ArcaeaPlayResultClearType(item["clear_type"])
|
||||
|
||||
if play_result.lost == 0:
|
||||
play_result.max_recall = play_result.pure + play_result.far
|
||||
|
||||
play_result.comment = f"Parsed from web API at {date_text}"
|
||||
results.append(play_result)
|
||||
return results
|
117
src/arcaea_offline/external/importers/arcaea/st3.py
vendored
Normal file
117
src/arcaea_offline/external/importers/arcaea/st3.py
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
"""
|
||||
Game database play results importer
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sqlite3
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, overload
|
||||
|
||||
from arcaea_offline.constants.enums import (
|
||||
ArcaeaPlayResultClearType,
|
||||
ArcaeaPlayResultModifier,
|
||||
ArcaeaRatingClass,
|
||||
)
|
||||
from arcaea_offline.database.models import PlayResult
|
||||
|
||||
from .common import fix_timestamp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ArcaeaSt3Parser:
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, db: sqlite3.Connection) -> List[PlayResult]: ...
|
||||
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, db: sqlite3.Cursor) -> List[PlayResult]: ...
|
||||
|
||||
@classmethod
|
||||
def parse(cls, db) -> List[PlayResult]:
|
||||
if isinstance(db, sqlite3.Connection):
|
||||
return cls.parse(db.cursor())
|
||||
|
||||
if not isinstance(db, sqlite3.Cursor):
|
||||
raise TypeError(
|
||||
"Unknown overload of `db`. Expected `sqlite3.Connection` or `sqlite3.Cursor`."
|
||||
)
|
||||
|
||||
entities = []
|
||||
query_results = db.execute("""
|
||||
SELECT s.id AS _id, s.songId, s.songDifficulty AS ratingClass, s.score,
|
||||
s.perfectCount AS pure, s.nearCount AS far, s.missCount AS lost,
|
||||
s.`date`, s.modifier, ct.clearType
|
||||
FROM scores s JOIN cleartypes ct
|
||||
ON s.songId = ct.songId AND s.songDifficulty = ct.songDifficulty""")
|
||||
# maybe `s.id = ct.id`?
|
||||
|
||||
now = datetime.now(tz=timezone.utc)
|
||||
import_comment = (
|
||||
f"Imported from st3 at {now.astimezone().isoformat(timespec='seconds')}"
|
||||
)
|
||||
for result in query_results:
|
||||
(
|
||||
_id,
|
||||
song_id,
|
||||
rating_class,
|
||||
score,
|
||||
pure,
|
||||
far,
|
||||
lost,
|
||||
date,
|
||||
modifier,
|
||||
clear_type,
|
||||
) = result
|
||||
|
||||
try:
|
||||
rating_class_enum = ArcaeaRatingClass(rating_class)
|
||||
except ValueError:
|
||||
logger.warning(
|
||||
"Unknown rating class [%r] at entry id %d, skipping!",
|
||||
rating_class,
|
||||
_id,
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
clear_type_enum = ArcaeaPlayResultClearType(clear_type)
|
||||
except ValueError:
|
||||
logger.warning(
|
||||
"Unknown clear type [%r] at entry id %d, falling back to `None`!",
|
||||
clear_type,
|
||||
_id,
|
||||
)
|
||||
clear_type_enum = None
|
||||
|
||||
try:
|
||||
modifier_enum = ArcaeaPlayResultModifier(modifier)
|
||||
except ValueError:
|
||||
logger.warning(
|
||||
"Unknown modifier [%r] at entry id %d, falling back to `None`!",
|
||||
modifier,
|
||||
_id,
|
||||
)
|
||||
modifier_enum = None
|
||||
|
||||
if date := fix_timestamp(date):
|
||||
date = datetime.fromtimestamp(date).astimezone()
|
||||
else:
|
||||
date = None
|
||||
|
||||
play_result = PlayResult()
|
||||
play_result.song_id = song_id
|
||||
play_result.rating_class = rating_class_enum
|
||||
play_result.score = score
|
||||
play_result.pure = pure
|
||||
play_result.far = far
|
||||
play_result.lost = lost
|
||||
play_result.played_at = date
|
||||
play_result.modifier = modifier_enum
|
||||
play_result.clear_type = clear_type_enum
|
||||
play_result.comment = import_comment
|
||||
|
||||
entities.append(play_result)
|
||||
|
||||
return entities
|
38
src/arcaea_offline/external/importers/arcsong.py
vendored
Normal file
38
src/arcaea_offline/external/importers/arcsong.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import sqlite3
|
||||
from typing import List, overload
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import ChartInfo
|
||||
|
||||
|
||||
class ArcsongDatabaseImporter:
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, conn: sqlite3.Connection) -> List[ChartInfo]: ...
|
||||
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, conn: sqlite3.Cursor) -> List[ChartInfo]: ...
|
||||
|
||||
@classmethod
|
||||
def parse(cls, conn) -> List[ChartInfo]:
|
||||
if isinstance(conn, sqlite3.Connection):
|
||||
return cls.parse(conn.cursor())
|
||||
|
||||
assert isinstance(conn, sqlite3.Cursor)
|
||||
|
||||
results = []
|
||||
db_results = conn.execute(
|
||||
"SELECT song_id, rating_class, rating, note FROM charts"
|
||||
)
|
||||
for result in db_results:
|
||||
results.append(
|
||||
ChartInfo(
|
||||
song_id=result[0],
|
||||
rating_class=ArcaeaRatingClass(result[1]),
|
||||
constant=result[2],
|
||||
notes=result[3] or None,
|
||||
)
|
||||
)
|
||||
|
||||
return results
|
42
src/arcaea_offline/external/importers/chart_info_database.py
vendored
Normal file
42
src/arcaea_offline/external/importers/chart_info_database.py
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
import sqlite3
|
||||
from contextlib import closing
|
||||
from typing import List, overload
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import ChartInfo
|
||||
|
||||
|
||||
class ChartInfoDatabaseParser:
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, conn: sqlite3.Connection) -> List[ChartInfo]: ...
|
||||
|
||||
@classmethod
|
||||
@overload
|
||||
def parse(cls, conn: sqlite3.Cursor) -> List[ChartInfo]: ...
|
||||
|
||||
@classmethod
|
||||
def parse(cls, conn) -> List[ChartInfo]:
|
||||
if isinstance(conn, sqlite3.Connection):
|
||||
with closing(conn.cursor()) as cur:
|
||||
return cls.parse(cur)
|
||||
|
||||
if not isinstance(conn, sqlite3.Cursor):
|
||||
raise ValueError("conn must be sqlite3.Connection or sqlite3.Cursor!")
|
||||
|
||||
db_items = conn.execute(
|
||||
"SELECT song_id, rating_class, constant, notes FROM charts_info"
|
||||
).fetchall()
|
||||
|
||||
results: List[ChartInfo] = []
|
||||
for item in db_items:
|
||||
(song_id, rating_class, constant, notes) = item
|
||||
|
||||
chart_info = ChartInfo()
|
||||
chart_info.song_id = song_id
|
||||
chart_info.rating_class = ArcaeaRatingClass(rating_class)
|
||||
chart_info.constant = constant
|
||||
chart_info.notes = notes
|
||||
|
||||
results.append(chart_info)
|
||||
return results
|
@ -1,21 +0,0 @@
|
||||
from .config import ConfigBase, Property
|
||||
from .scores import (
|
||||
CalculatedPotential,
|
||||
Score,
|
||||
ScoreBest,
|
||||
ScoreCalculated,
|
||||
ScoresBase,
|
||||
ScoresViewBase,
|
||||
)
|
||||
from .songs import (
|
||||
Chart,
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
DifficultyLocalized,
|
||||
Pack,
|
||||
PackLocalized,
|
||||
Song,
|
||||
SongLocalized,
|
||||
SongsBase,
|
||||
SongsViewBase,
|
||||
)
|
@ -1,20 +0,0 @@
|
||||
from sqlalchemy import TEXT
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
from .common import ReprHelper
|
||||
|
||||
__all__ = [
|
||||
"ConfigBase",
|
||||
"Property",
|
||||
]
|
||||
|
||||
|
||||
class ConfigBase(DeclarativeBase, ReprHelper):
|
||||
pass
|
||||
|
||||
|
||||
class Property(ConfigBase):
|
||||
__tablename__ = "properties"
|
||||
|
||||
key: Mapped[str] = mapped_column(TEXT(), primary_key=True)
|
||||
value: Mapped[str] = mapped_column(TEXT())
|
@ -1,174 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import TEXT, case, func, inspect, select
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
from sqlalchemy_utils import create_view
|
||||
|
||||
from .common import ReprHelper
|
||||
from .songs import ChartInfo, Difficulty
|
||||
|
||||
__all__ = [
|
||||
"ScoresBase",
|
||||
"Score",
|
||||
"ScoresViewBase",
|
||||
"ScoreCalculated",
|
||||
"ScoreBest",
|
||||
"CalculatedPotential",
|
||||
]
|
||||
|
||||
|
||||
class ScoresBase(DeclarativeBase, ReprHelper):
|
||||
pass
|
||||
|
||||
|
||||
class Score(ScoresBase):
|
||||
__tablename__ = "scores"
|
||||
|
||||
id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)
|
||||
song_id: Mapped[str] = mapped_column(TEXT())
|
||||
rating_class: Mapped[int]
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
date: Mapped[Optional[int]]
|
||||
max_recall: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]] = mapped_column(
|
||||
comment="0: NORMAL, 1: EASY, 2: HARD"
|
||||
)
|
||||
clear_type: Mapped[Optional[int]] = mapped_column(
|
||||
comment="0: TRACK LOST, 1: NORMAL CLEAR, 2: FULL RECALL, 3: PURE MEMORY, 4: EASY CLEAR, 5: HARD CLEAR"
|
||||
)
|
||||
comment: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
# How to create an SQL View with SQLAlchemy?
|
||||
# https://stackoverflow.com/a/53253105/16484891
|
||||
# CC BY-SA 4.0
|
||||
|
||||
|
||||
class ScoresViewBase(DeclarativeBase, ReprHelper):
|
||||
pass
|
||||
|
||||
|
||||
class ScoreCalculated(ScoresViewBase):
|
||||
__tablename__ = "scores_calculated"
|
||||
|
||||
id: Mapped[int]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
shiny_pure: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
date: Mapped[Optional[int]]
|
||||
max_recall: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]]
|
||||
clear_type: Mapped[Optional[int]]
|
||||
potential: Mapped[float]
|
||||
comment: Mapped[Optional[str]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
Score.id,
|
||||
Difficulty.song_id,
|
||||
Difficulty.rating_class,
|
||||
Score.score,
|
||||
Score.pure,
|
||||
(
|
||||
Score.score
|
||||
- func.floor(
|
||||
(Score.pure * 10000000.0 / ChartInfo.notes)
|
||||
+ (Score.far * 0.5 * 10000000.0 / ChartInfo.notes)
|
||||
)
|
||||
).label("shiny_pure"),
|
||||
Score.far,
|
||||
Score.lost,
|
||||
Score.date,
|
||||
Score.max_recall,
|
||||
Score.modifier,
|
||||
Score.clear_type,
|
||||
case(
|
||||
(Score.score >= 10000000, ChartInfo.constant / 10.0 + 2),
|
||||
(
|
||||
Score.score >= 9800000,
|
||||
ChartInfo.constant / 10.0 + 1 + (Score.score - 9800000) / 200000.0,
|
||||
),
|
||||
else_=func.max(
|
||||
(ChartInfo.constant / 10.0) + (Score.score - 9500000) / 300000.0,
|
||||
0,
|
||||
),
|
||||
).label("potential"),
|
||||
Score.comment,
|
||||
)
|
||||
.select_from(Difficulty)
|
||||
.join(
|
||||
ChartInfo,
|
||||
(Difficulty.song_id == ChartInfo.song_id)
|
||||
& (Difficulty.rating_class == ChartInfo.rating_class),
|
||||
)
|
||||
.join(
|
||||
Score,
|
||||
(Difficulty.song_id == Score.song_id)
|
||||
& (Difficulty.rating_class == Score.rating_class),
|
||||
),
|
||||
metadata=ScoresViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
||||
|
||||
|
||||
class ScoreBest(ScoresViewBase):
|
||||
__tablename__ = "scores_best"
|
||||
|
||||
id: Mapped[int]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
score: Mapped[int]
|
||||
pure: Mapped[Optional[int]]
|
||||
shiny_pure: Mapped[Optional[int]]
|
||||
far: Mapped[Optional[int]]
|
||||
lost: Mapped[Optional[int]]
|
||||
date: Mapped[Optional[int]]
|
||||
max_recall: Mapped[Optional[int]]
|
||||
modifier: Mapped[Optional[int]]
|
||||
clear_type: Mapped[Optional[int]]
|
||||
potential: Mapped[float]
|
||||
comment: Mapped[Optional[str]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
*[
|
||||
col
|
||||
for col in inspect(ScoreCalculated).columns
|
||||
if col.name != "potential"
|
||||
],
|
||||
func.max(ScoreCalculated.potential).label("potential"),
|
||||
)
|
||||
.select_from(ScoreCalculated)
|
||||
.group_by(ScoreCalculated.song_id, ScoreCalculated.rating_class)
|
||||
.order_by(ScoreCalculated.potential.desc()),
|
||||
metadata=ScoresViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
||||
|
||||
|
||||
class CalculatedPotential(ScoresViewBase):
|
||||
__tablename__ = "calculated_potential"
|
||||
|
||||
b30: Mapped[float]
|
||||
|
||||
_select_bests_subquery = (
|
||||
select(ScoreBest.potential.label("b30_sum"))
|
||||
.order_by(ScoreBest.potential.desc())
|
||||
.limit(30)
|
||||
.subquery()
|
||||
)
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(func.avg(_select_bests_subquery.c.b30_sum).label("b30")),
|
||||
metadata=ScoresViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
@ -1,239 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import TEXT, ForeignKey, func, select
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
from sqlalchemy_utils import create_view
|
||||
|
||||
from .common import ReprHelper
|
||||
|
||||
__all__ = [
|
||||
"SongsBase",
|
||||
"Pack",
|
||||
"PackLocalized",
|
||||
"Song",
|
||||
"SongLocalized",
|
||||
"Difficulty",
|
||||
"DifficultyLocalized",
|
||||
"ChartInfo",
|
||||
"SongsViewBase",
|
||||
"Chart",
|
||||
]
|
||||
|
||||
|
||||
class SongsBase(DeclarativeBase, ReprHelper):
|
||||
pass
|
||||
|
||||
|
||||
class Pack(SongsBase):
|
||||
__tablename__ = "packs"
|
||||
|
||||
id: Mapped[str] = mapped_column(TEXT(), primary_key=True)
|
||||
name: Mapped[str] = mapped_column(TEXT())
|
||||
description: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
class PackLocalized(SongsBase):
|
||||
__tablename__ = "packs_localized"
|
||||
|
||||
id: Mapped[str] = mapped_column(ForeignKey("packs.id"), primary_key=True)
|
||||
name_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
name_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
name_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
name_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
description_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
description_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
description_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
description_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
class Song(SongsBase):
|
||||
__tablename__ = "songs"
|
||||
|
||||
idx: Mapped[int]
|
||||
id: Mapped[str] = mapped_column(TEXT(), primary_key=True)
|
||||
title: Mapped[str] = mapped_column(TEXT())
|
||||
artist: Mapped[str] = mapped_column(TEXT())
|
||||
set: Mapped[str] = mapped_column(TEXT())
|
||||
bpm: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bpm_base: Mapped[Optional[float]]
|
||||
audio_preview: Mapped[Optional[int]]
|
||||
audio_preview_end: Mapped[Optional[int]]
|
||||
side: Mapped[Optional[int]]
|
||||
version: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
date: Mapped[Optional[int]]
|
||||
bg: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bg_inverse: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bg_day: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bg_night: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
source: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
source_copyright: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
class SongLocalized(SongsBase):
|
||||
__tablename__ = "songs_localized"
|
||||
|
||||
id: Mapped[str] = mapped_column(ForeignKey("songs.id"), primary_key=True)
|
||||
title_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
search_title_ja: Mapped[Optional[str]] = mapped_column(TEXT(), comment="JSON array")
|
||||
search_title_ko: Mapped[Optional[str]] = mapped_column(TEXT(), comment="JSON array")
|
||||
search_title_zh_hans: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
search_title_zh_hant: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
search_artist_ja: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
search_artist_ko: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
search_artist_zh_hans: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
search_artist_zh_hant: Mapped[Optional[str]] = mapped_column(
|
||||
TEXT(), comment="JSON array"
|
||||
)
|
||||
source_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
source_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
source_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
source_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
class Difficulty(SongsBase):
|
||||
__tablename__ = "difficulties"
|
||||
|
||||
song_id: Mapped[str] = mapped_column(TEXT(), primary_key=True)
|
||||
rating_class: Mapped[int] = mapped_column(primary_key=True)
|
||||
rating: Mapped[int]
|
||||
rating_plus: Mapped[bool]
|
||||
chart_designer: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
jacket_desginer: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
audio_override: Mapped[bool]
|
||||
jacket_override: Mapped[bool]
|
||||
jacket_night: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
artist: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bg: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bg_inverse: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bpm: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
bpm_base: Mapped[Optional[float]]
|
||||
version: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
date: Mapped[Optional[int]]
|
||||
|
||||
|
||||
class DifficultyLocalized(SongsBase):
|
||||
__tablename__ = "difficulties_localized"
|
||||
|
||||
song_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("difficulties.song_id"), primary_key=True
|
||||
)
|
||||
rating_class: Mapped[str] = mapped_column(
|
||||
ForeignKey("difficulties.rating_class"), primary_key=True
|
||||
)
|
||||
title_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
title_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
artist_ja: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
artist_ko: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
artist_zh_hans: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
artist_zh_hant: Mapped[Optional[str]] = mapped_column(TEXT())
|
||||
|
||||
|
||||
class ChartInfo(SongsBase):
|
||||
__tablename__ = "charts_info"
|
||||
|
||||
song_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("difficulties.song_id"), primary_key=True
|
||||
)
|
||||
rating_class: Mapped[str] = mapped_column(
|
||||
ForeignKey("difficulties.rating_class"), primary_key=True
|
||||
)
|
||||
constant: Mapped[int] = mapped_column(
|
||||
comment="real_constant * 10. For example, Crimson Throne [FTR] is 10.4, then store 104 here."
|
||||
)
|
||||
notes: Mapped[Optional[int]]
|
||||
|
||||
|
||||
class SongsViewBase(DeclarativeBase, ReprHelper):
|
||||
pass
|
||||
|
||||
|
||||
class Chart(SongsViewBase):
|
||||
__tablename__ = "charts"
|
||||
|
||||
song_idx: Mapped[int]
|
||||
song_id: Mapped[str]
|
||||
rating_class: Mapped[int]
|
||||
rating: Mapped[int]
|
||||
rating_plus: Mapped[bool]
|
||||
title: Mapped[str]
|
||||
artist: Mapped[str]
|
||||
set: Mapped[str]
|
||||
bpm: Mapped[Optional[str]]
|
||||
bpm_base: Mapped[Optional[float]]
|
||||
audio_preview: Mapped[Optional[int]]
|
||||
audio_preview_end: Mapped[Optional[int]]
|
||||
side: Mapped[Optional[int]]
|
||||
version: Mapped[Optional[str]]
|
||||
date: Mapped[Optional[int]]
|
||||
bg: Mapped[Optional[str]]
|
||||
bg_inverse: Mapped[Optional[str]]
|
||||
bg_day: Mapped[Optional[str]]
|
||||
bg_night: Mapped[Optional[str]]
|
||||
source: Mapped[Optional[str]]
|
||||
source_copyright: Mapped[Optional[str]]
|
||||
chart_designer: Mapped[Optional[str]]
|
||||
jacket_desginer: Mapped[Optional[str]]
|
||||
audio_override: Mapped[bool]
|
||||
jacket_override: Mapped[bool]
|
||||
jacket_night: Mapped[Optional[str]]
|
||||
constant: Mapped[int]
|
||||
notes: Mapped[Optional[int]]
|
||||
|
||||
__table__ = create_view(
|
||||
name=__tablename__,
|
||||
selectable=select(
|
||||
Song.idx.label("song_idx"),
|
||||
Difficulty.song_id,
|
||||
Difficulty.rating_class,
|
||||
Difficulty.rating,
|
||||
Difficulty.rating_plus,
|
||||
func.coalesce(Difficulty.title, Song.title).label("title"),
|
||||
func.coalesce(Difficulty.artist, Song.artist).label("artist"),
|
||||
Song.set,
|
||||
func.coalesce(Difficulty.bpm, Song.bpm).label("bpm"),
|
||||
func.coalesce(Difficulty.bpm_base, Song.bpm_base).label("bpm_base"),
|
||||
Song.audio_preview,
|
||||
Song.audio_preview_end,
|
||||
Song.side,
|
||||
func.coalesce(Difficulty.version, Song.version).label("version"),
|
||||
func.coalesce(Difficulty.date, Song.date).label("date"),
|
||||
func.coalesce(Difficulty.bg, Song.bg).label("bg"),
|
||||
func.coalesce(Difficulty.bg_inverse, Song.bg_inverse).label("bg_inverse"),
|
||||
Song.bg_day,
|
||||
Song.bg_night,
|
||||
Song.source,
|
||||
Song.source_copyright,
|
||||
Difficulty.chart_designer,
|
||||
Difficulty.jacket_desginer,
|
||||
Difficulty.audio_override,
|
||||
Difficulty.jacket_override,
|
||||
Difficulty.jacket_night,
|
||||
ChartInfo.constant,
|
||||
ChartInfo.notes,
|
||||
)
|
||||
.select_from(Difficulty)
|
||||
.join(
|
||||
ChartInfo,
|
||||
(Difficulty.song_id == ChartInfo.song_id)
|
||||
& (Difficulty.rating_class == ChartInfo.rating_class),
|
||||
)
|
||||
.join(Song, Difficulty.song_id == Song.id),
|
||||
metadata=SongsViewBase.metadata,
|
||||
cascade_on_drop=False,
|
||||
)
|
@ -1,111 +0,0 @@
|
||||
from typing import List, Union
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from whoosh.analysis import NgramFilter, StandardAnalyzer
|
||||
from whoosh.fields import ID, KEYWORD, TEXT, Schema
|
||||
from whoosh.filedb.filestore import RamStorage
|
||||
from whoosh.qparser import FuzzyTermPlugin, MultifieldParser, OrGroup
|
||||
|
||||
from .models.songs import Song, SongLocalized
|
||||
from .utils.search_title import recover_search_title
|
||||
|
||||
|
||||
class Searcher:
|
||||
def __init__(self):
|
||||
self.text_analyzer = StandardAnalyzer() | NgramFilter(minsize=2, maxsize=5)
|
||||
self.song_schema = Schema(
|
||||
song_id=ID(stored=True, unique=True),
|
||||
title=TEXT(analyzer=self.text_analyzer, spelling=True),
|
||||
artist=TEXT(analyzer=self.text_analyzer, spelling=True),
|
||||
source=TEXT(analyzer=self.text_analyzer, spelling=True),
|
||||
keywords=KEYWORD(lowercase=True, stored=True, scorable=True),
|
||||
)
|
||||
self.storage = RamStorage()
|
||||
self.index = self.storage.create_index(self.song_schema)
|
||||
|
||||
self.default_query_parser = MultifieldParser(
|
||||
["song_id", "title", "artist", "source", "keywords"],
|
||||
self.song_schema,
|
||||
group=OrGroup,
|
||||
)
|
||||
self.default_query_parser.add_plugin(FuzzyTermPlugin())
|
||||
|
||||
def import_songs(self, session: Session):
|
||||
writer = self.index.writer()
|
||||
songs = list(session.scalars(select(Song)))
|
||||
song_localize_stmt = select(SongLocalized)
|
||||
for song in songs:
|
||||
stmt = song_localize_stmt.where(SongLocalized.id == song.id)
|
||||
sl = session.scalar(stmt)
|
||||
song_id = song.id
|
||||
possible_titles: List[Union[str, None]] = [song.title]
|
||||
possible_artists: List[Union[str, None]] = [song.artist]
|
||||
possible_sources: List[Union[str, None]] = [song.source]
|
||||
if sl:
|
||||
possible_titles.extend(
|
||||
[sl.title_ja, sl.title_ko, sl.title_zh_hans, sl.title_zh_hant]
|
||||
)
|
||||
possible_titles.extend(
|
||||
recover_search_title(sl.search_title_ja)
|
||||
+ recover_search_title(sl.search_title_ko)
|
||||
+ recover_search_title(sl.search_title_zh_hans)
|
||||
+ recover_search_title(sl.search_title_zh_hant)
|
||||
)
|
||||
possible_artists.extend(
|
||||
recover_search_title(sl.search_artist_ja)
|
||||
+ recover_search_title(sl.search_artist_ko)
|
||||
+ recover_search_title(sl.search_artist_zh_hans)
|
||||
+ recover_search_title(sl.search_artist_zh_hant)
|
||||
)
|
||||
possible_sources.extend(
|
||||
[
|
||||
sl.source_ja,
|
||||
sl.source_ko,
|
||||
sl.source_zh_hans,
|
||||
sl.source_zh_hant,
|
||||
]
|
||||
)
|
||||
|
||||
# remove empty items in list
|
||||
titles = [t for t in possible_titles if t != "" and t is not None]
|
||||
artists = [t for t in possible_artists if t != "" and t is not None]
|
||||
sources = [t for t in possible_sources if t != "" and t is not None]
|
||||
|
||||
writer.update_document(
|
||||
song_id=song_id,
|
||||
title=" ".join(titles),
|
||||
artist=" ".join(artists),
|
||||
source=" ".join(sources),
|
||||
keywords=" ".join([song_id] + titles + artists + sources),
|
||||
)
|
||||
|
||||
writer.commit()
|
||||
|
||||
def did_you_mean(self, string: str):
|
||||
results = set()
|
||||
|
||||
with self.index.searcher() as searcher:
|
||||
corrector_keywords = searcher.corrector("keywords") # type: ignore
|
||||
corrector_song_id = searcher.corrector("song_id") # type: ignore
|
||||
corrector_title = searcher.corrector("title") # type: ignore
|
||||
corrector_artist = searcher.corrector("artist") # type: ignore
|
||||
corrector_source = searcher.corrector("source") # type: ignore
|
||||
|
||||
results.update(corrector_keywords.suggest(string))
|
||||
results.update(corrector_song_id.suggest(string))
|
||||
results.update(corrector_title.suggest(string))
|
||||
results.update(corrector_artist.suggest(string))
|
||||
results.update(corrector_source.suggest(string))
|
||||
|
||||
if string in results:
|
||||
results.remove(string)
|
||||
|
||||
return list(results)
|
||||
|
||||
def search(self, string: str, *, limit: int = 10, fuzzy_distance: int = 10):
|
||||
query_string = f"{string}"
|
||||
query = self.default_query_parser.parse(query_string)
|
||||
with self.index.searcher() as searcher:
|
||||
results = searcher.search(query, limit=limit)
|
||||
return [result.get("song_id") for result in results]
|
@ -1,12 +0,0 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class Singleton(type, Generic[T]):
|
||||
_instance = None
|
||||
|
||||
def __call__(cls, *args, **kwargs) -> T:
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__call__(*args, **kwargs)
|
||||
return cls._instance
|
7
src/arcaea_offline/utils/formatters/__init__.py
Normal file
7
src/arcaea_offline/utils/formatters/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
from .play_result import PlayResultFormatter
|
||||
from .rating_class import RatingClassFormatter
|
||||
|
||||
__all__ = [
|
||||
"PlayResultFormatter",
|
||||
"RatingClassFormatter",
|
||||
]
|
135
src/arcaea_offline/utils/formatters/play_result.py
Normal file
135
src/arcaea_offline/utils/formatters/play_result.py
Normal file
@ -0,0 +1,135 @@
|
||||
from typing import Any, Dict, Literal, overload
|
||||
|
||||
from arcaea_offline.constants.enums import (
|
||||
ArcaeaPlayResultClearType,
|
||||
ArcaeaPlayResultModifier,
|
||||
)
|
||||
from arcaea_offline.constants.play_result import ScoreLowerLimits
|
||||
|
||||
|
||||
class PlayResultFormatter:
|
||||
SCORE_GRADE_FORMAT_RESULTS = Literal["EX+", "EX", "AA", "A", "B", "C", "D"]
|
||||
|
||||
@classmethod
|
||||
def score_grade(cls, score: int) -> SCORE_GRADE_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the score grade, e.g. EX+.
|
||||
|
||||
Raises `ValueError` if the score is negative.
|
||||
"""
|
||||
if not isinstance(score, int):
|
||||
raise TypeError(f"Unsupported type {type(score)}, cannot format")
|
||||
|
||||
if score < 0:
|
||||
raise ValueError("score cannot be negative")
|
||||
|
||||
score_grades: Dict[int, Literal["EX+", "EX", "AA", "A", "B", "C", "D"]] = {
|
||||
ScoreLowerLimits.EX_PLUS: "EX+",
|
||||
ScoreLowerLimits.EX: "EX",
|
||||
ScoreLowerLimits.AA: "AA",
|
||||
ScoreLowerLimits.A: "A",
|
||||
ScoreLowerLimits.B: "B",
|
||||
ScoreLowerLimits.C: "C",
|
||||
ScoreLowerLimits.D: "D",
|
||||
}
|
||||
|
||||
return next(value for limit, value in score_grades.items() if score >= limit)
|
||||
|
||||
CLEAR_TYPE_FORMAT_RESULTS = Literal[
|
||||
"TRACK LOST",
|
||||
"NORMAL CLEAR",
|
||||
"FULL RECALL",
|
||||
"PURE MEMORY",
|
||||
"EASY CLEAR",
|
||||
"HARD CLEAR",
|
||||
"UNKNOWN",
|
||||
"None",
|
||||
]
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def clear_type(
|
||||
cls, clear_type: ArcaeaPlayResultClearType
|
||||
) -> CLEAR_TYPE_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased clear type name, e.g. NORMAL CLEAR.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def clear_type(cls, clear_type: int) -> CLEAR_TYPE_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased clear type name, e.g. NORMAL CLEAR.
|
||||
|
||||
The integer will be converted to `ArcaeaPlayResultClearType` enum,
|
||||
and will return "UNKNOWN" if the convertion fails.
|
||||
|
||||
Raises `ValueError` if the integer is negative.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def clear_type(cls, clear_type: None) -> CLEAR_TYPE_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns "None"
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def clear_type(cls, clear_type: Any) -> CLEAR_TYPE_FORMAT_RESULTS:
|
||||
if clear_type is None:
|
||||
return "None"
|
||||
elif isinstance(clear_type, ArcaeaPlayResultClearType):
|
||||
return clear_type.name.replace("_", " ").upper() # type: ignore
|
||||
elif isinstance(clear_type, int):
|
||||
if clear_type < 0:
|
||||
raise ValueError("clear_type cannot be negative")
|
||||
try:
|
||||
return cls.clear_type(ArcaeaPlayResultClearType(clear_type))
|
||||
except ValueError:
|
||||
return "UNKNOWN"
|
||||
else:
|
||||
raise TypeError(f"Unsupported type {type(clear_type)}, cannot format")
|
||||
|
||||
MODIFIER_FORMAT_RESULTS = Literal["NORMAL", "EASY", "HARD", "UNKNOWN", "None"]
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def modifier(cls, modifier: ArcaeaPlayResultModifier) -> MODIFIER_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased clear type name, e.g. NORMAL CLEAR.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def modifier(cls, modifier: int) -> MODIFIER_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased clear type name, e.g. NORMAL CLEAR.
|
||||
|
||||
The integer will be converted to `ArcaeaPlayResultModifier` enum,
|
||||
and will return "UNKNOWN" if the convertion fails.
|
||||
|
||||
Raises `ValueError` if the integer is negative.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def modifier(cls, modifier: None) -> MODIFIER_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns "None"
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def modifier(cls, modifier: Any) -> MODIFIER_FORMAT_RESULTS:
|
||||
if modifier is None:
|
||||
return "None"
|
||||
elif isinstance(modifier, ArcaeaPlayResultModifier):
|
||||
return modifier.name
|
||||
elif isinstance(modifier, int):
|
||||
if modifier < 0:
|
||||
raise ValueError("modifier cannot be negative")
|
||||
try:
|
||||
return cls.modifier(ArcaeaPlayResultModifier(modifier))
|
||||
except ValueError:
|
||||
return "UNKNOWN"
|
||||
else:
|
||||
raise TypeError(f"Unsupported type {type(modifier)}, cannot format")
|
79
src/arcaea_offline/utils/formatters/rating_class.py
Normal file
79
src/arcaea_offline/utils/formatters/rating_class.py
Normal file
@ -0,0 +1,79 @@
|
||||
from typing import Any, Literal, overload
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaRatingClass
|
||||
|
||||
|
||||
class RatingClassFormatter:
|
||||
abbreviations = {
|
||||
ArcaeaRatingClass.PAST: "PST",
|
||||
ArcaeaRatingClass.PRESENT: "PRS",
|
||||
ArcaeaRatingClass.FUTURE: "FTR",
|
||||
ArcaeaRatingClass.BEYOND: "BYD",
|
||||
ArcaeaRatingClass.ETERNAL: "ETR",
|
||||
}
|
||||
|
||||
NAME_FORMAT_RESULTS = Literal[
|
||||
"Past", "Present", "Future", "Beyond", "Eternal", "Unknown"
|
||||
]
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def name(cls, rating_class: ArcaeaRatingClass) -> NAME_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the capitalized rating class name, e.g. Future.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def name(cls, rating_class: int) -> NAME_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the capitalized rating class name, e.g. Future.
|
||||
|
||||
The integer will be converted to `ArcaeaRatingClass` enum,
|
||||
and will return "Unknown" if the convertion fails.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def name(cls, rating_class: Any) -> NAME_FORMAT_RESULTS:
|
||||
if isinstance(rating_class, ArcaeaRatingClass):
|
||||
return rating_class.name.lower().capitalize() # type: ignore
|
||||
elif isinstance(rating_class, int):
|
||||
try:
|
||||
return cls.name(ArcaeaRatingClass(rating_class))
|
||||
except ValueError:
|
||||
return "Unknown"
|
||||
else:
|
||||
raise TypeError(f"Unsupported type: {type(rating_class)}, cannot format")
|
||||
|
||||
ABBREVIATION_FORMAT_RESULTS = Literal["PST", "PRS", "FTR", "BYD", "ETR", "UNK"]
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def abbreviation(
|
||||
cls, rating_class: ArcaeaRatingClass
|
||||
) -> ABBREVIATION_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased rating class name, e.g. FTR.
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def abbreviation(cls, rating_class: int) -> ABBREVIATION_FORMAT_RESULTS:
|
||||
"""
|
||||
Returns the uppercased rating class name, e.g. FTR.
|
||||
|
||||
The integer will be converted to `ArcaeaRatingClass` enum,
|
||||
and will return "UNK" if the convertion fails.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def abbreviation(cls, rating_class: Any) -> ABBREVIATION_FORMAT_RESULTS:
|
||||
if isinstance(rating_class, ArcaeaRatingClass):
|
||||
return cls.abbreviations[rating_class] # type: ignore
|
||||
elif isinstance(rating_class, int):
|
||||
try:
|
||||
return cls.abbreviation(ArcaeaRatingClass(rating_class))
|
||||
except ValueError:
|
||||
return "UNK"
|
||||
else:
|
||||
raise TypeError(f"Unsupported type: {type(rating_class)}, cannot format")
|
11
src/arcaea_offline/utils/partner.py
Normal file
11
src/arcaea_offline/utils/partner.py
Normal file
@ -0,0 +1,11 @@
|
||||
from datetime import datetime
|
||||
from enum import IntEnum
|
||||
|
||||
|
||||
class KanaeDayNight(IntEnum):
|
||||
DAY = 0
|
||||
NIGHT = 1
|
||||
|
||||
@staticmethod
|
||||
def from_datetime(dt: datetime) -> "KanaeDayNight":
|
||||
return KanaeDayNight.DAY if 6 <= dt.hour <= 19 else KanaeDayNight.NIGHT # noqa: PLR2004
|
@ -1,23 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
RATING_CLASS_TEXT_MAP = {
|
||||
0: "Past",
|
||||
1: "Present",
|
||||
2: "Future",
|
||||
3: "Beyond",
|
||||
}
|
||||
|
||||
RATING_CLASS_SHORT_TEXT_MAP = {
|
||||
0: "PST",
|
||||
1: "PRS",
|
||||
2: "FTR",
|
||||
3: "BYD",
|
||||
}
|
||||
|
||||
|
||||
def rating_class_to_text(rating_class: int) -> Optional[str]:
|
||||
return RATING_CLASS_TEXT_MAP.get(rating_class)
|
||||
|
||||
|
||||
def rating_class_to_short_text(rating_class: int) -> Optional[str]:
|
||||
return RATING_CLASS_SHORT_TEXT_MAP.get(rating_class)
|
@ -1,29 +0,0 @@
|
||||
from typing import Any, Sequence
|
||||
|
||||
SCORE_GRADE_FLOOR = [9900000, 9800000, 9500000, 9200000, 8900000, 8600000, 0]
|
||||
SCORE_GRADE_TEXTS = ["EX+", "EX", "AA", "A", "B", "C", "D"]
|
||||
|
||||
|
||||
def zip_score_grade(score: int, __seq: Sequence, default: Any = "__PRESERVE__"):
|
||||
"""
|
||||
zip_score_grade is a simple wrapper that equals to:
|
||||
```py
|
||||
for score_floor, val in zip(SCORE_GRADE_FLOOR, __seq):
|
||||
if score >= score_floor:
|
||||
return val
|
||||
return seq[-1] if default == "__PRESERVE__" else default
|
||||
```
|
||||
Could be useful in specific cases.
|
||||
"""
|
||||
return next(
|
||||
(
|
||||
val
|
||||
for score_floor, val in zip(SCORE_GRADE_FLOOR, __seq)
|
||||
if score >= score_floor
|
||||
),
|
||||
__seq[-1] if default == "__PRESERVE__" else default,
|
||||
)
|
||||
|
||||
|
||||
def score_to_grade_text(score: int) -> str:
|
||||
return zip_score_grade(score, SCORE_GRADE_TEXTS)
|
@ -1,6 +0,0 @@
|
||||
import json
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
def recover_search_title(db_value: Optional[str]) -> List[str]:
|
||||
return json.loads(db_value) if db_value else []
|
46
tests/calculators/test_play_result.py
Normal file
46
tests/calculators/test_play_result.py
Normal file
@ -0,0 +1,46 @@
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from arcaea_offline.calculators.play_result import PlayResultCalculators
|
||||
|
||||
|
||||
class TestPlayResultCalculators:
|
||||
def test_score_modifier(self):
|
||||
# Results from https://arcaea.fandom.com/wiki/Potential#Score_Modifier
|
||||
|
||||
assert PlayResultCalculators.score_modifier(10000000) == Decimal("2.0")
|
||||
assert PlayResultCalculators.score_modifier(9900000) == Decimal("1.5")
|
||||
assert PlayResultCalculators.score_modifier(9800000) == Decimal("1.0")
|
||||
assert PlayResultCalculators.score_modifier(9500000) == Decimal("0.0")
|
||||
assert PlayResultCalculators.score_modifier(9200000) == Decimal("-1.0")
|
||||
assert PlayResultCalculators.score_modifier(8900000) == Decimal("-2.0")
|
||||
assert PlayResultCalculators.score_modifier(8600000) == Decimal("-3.0")
|
||||
|
||||
assert PlayResultCalculators.score_modifier(0).quantize(
|
||||
Decimal("-0.00")
|
||||
) == Decimal("-31.67")
|
||||
|
||||
with pytest.raises(ValueError, match="negative"):
|
||||
PlayResultCalculators.score_modifier(-1)
|
||||
|
||||
pytest.raises(TypeError, PlayResultCalculators.score_modifier, "9800000")
|
||||
pytest.raises(TypeError, PlayResultCalculators.score_modifier, None)
|
||||
pytest.raises(TypeError, PlayResultCalculators.score_modifier, [])
|
||||
|
||||
def test_play_rating(self):
|
||||
assert PlayResultCalculators.play_rating(10002221, 120) == Decimal("14.0")
|
||||
|
||||
assert PlayResultCalculators.play_rating(5500000, 120) == Decimal("0.0")
|
||||
|
||||
pytest.raises(TypeError, PlayResultCalculators.play_rating, "10002221", 120)
|
||||
pytest.raises(TypeError, PlayResultCalculators.play_rating, 10002221, "120")
|
||||
pytest.raises(TypeError, PlayResultCalculators.play_rating, "10002221", "120")
|
||||
|
||||
pytest.raises(TypeError, PlayResultCalculators.play_rating, 10002221, None)
|
||||
|
||||
with pytest.raises(ValueError, match="negative"):
|
||||
PlayResultCalculators.play_rating(-1, 120)
|
||||
|
||||
with pytest.raises(ValueError, match="negative"):
|
||||
PlayResultCalculators.play_rating(10002221, -1)
|
74
tests/calculators/test_world.py
Normal file
74
tests/calculators/test_world.py
Normal file
@ -0,0 +1,74 @@
|
||||
from decimal import ROUND_FLOOR, Decimal
|
||||
|
||||
from arcaea_offline.calculators.play_result import PlayResultCalculators
|
||||
from arcaea_offline.calculators.world import (
|
||||
LegacyMapStepBooster,
|
||||
PartnerBonus,
|
||||
WorldMainMapCalculators,
|
||||
WorldPlayResult,
|
||||
)
|
||||
|
||||
|
||||
class TestWorldMainMapCalculators:
|
||||
def test_step_fandom(self):
|
||||
# Final result from https://arcaea.fandom.com/wiki/World_Mode_Mechanics#Calculation
|
||||
# CC BY-SA 3.0
|
||||
|
||||
booster = LegacyMapStepBooster(6, 250)
|
||||
partner_bonus = PartnerBonus(step_bonus="+3.6")
|
||||
play_result = WorldPlayResult(play_rating=Decimal("11.299"), partner_step=92)
|
||||
result = WorldMainMapCalculators.step(
|
||||
play_result, partner_bonus=partner_bonus, step_booster=booster
|
||||
)
|
||||
|
||||
assert result.quantize(Decimal("0.000")) == Decimal("175.149")
|
||||
|
||||
def test_step(self):
|
||||
# Results from actual play results, Arcaea v5.5.8c
|
||||
|
||||
def _quantize(decimal: Decimal) -> Decimal:
|
||||
return decimal.quantize(Decimal("0.0"), rounding=ROUND_FLOOR)
|
||||
|
||||
# goldenslaughter FTR [9.7], 9906968
|
||||
# 10.7 > 34.2 < 160
|
||||
assert _quantize(
|
||||
WorldMainMapCalculators.step(
|
||||
WorldPlayResult(
|
||||
play_rating=PlayResultCalculators.play_rating(9906968, 97),
|
||||
partner_step=160,
|
||||
)
|
||||
)
|
||||
) == Decimal("34.2")
|
||||
|
||||
# Luna Rossa FTR [9.7], 9984569
|
||||
# 10.8 > 34.7 < 160
|
||||
assert _quantize(
|
||||
WorldMainMapCalculators.step(
|
||||
WorldPlayResult(
|
||||
play_rating=PlayResultCalculators.play_rating(9984569, 97),
|
||||
partner_step=160,
|
||||
)
|
||||
)
|
||||
) == Decimal("34.7")
|
||||
|
||||
# ultradiaxon-N3 FTR [10.5], 9349575
|
||||
# 10.2 > 32.7 < 160
|
||||
assert _quantize(
|
||||
WorldMainMapCalculators.step(
|
||||
WorldPlayResult(
|
||||
play_rating=PlayResultCalculators.play_rating(9349575, 105),
|
||||
partner_step=160,
|
||||
)
|
||||
)
|
||||
) == Decimal("32.7")
|
||||
|
||||
# san skia FTR [8.3], 10001036
|
||||
# 10.3 > 64.2 < 310
|
||||
assert _quantize(
|
||||
WorldMainMapCalculators.step(
|
||||
WorldPlayResult(
|
||||
play_rating=PlayResultCalculators.play_rating(10001036, 83),
|
||||
partner_step=310,
|
||||
)
|
||||
)
|
||||
) == Decimal("64.2")
|
53
tests/conftest.py
Normal file
53
tests/conftest.py
Normal file
@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
# region sqlalchemy fixtures
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
Session = sessionmaker()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def db_conn():
|
||||
conn = engine.connect()
|
||||
yield conn
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db_session(db_conn):
|
||||
session = Session(bind=db_conn)
|
||||
yield session
|
||||
session.close()
|
||||
|
||||
# drop everything
|
||||
query_tables = db_conn.execute(
|
||||
text("SELECT name FROM sqlite_master WHERE type='table'")
|
||||
).fetchall()
|
||||
for row in query_tables:
|
||||
table_name = row[0]
|
||||
db_conn.execute(text(f"DROP TABLE {table_name}"))
|
||||
|
||||
query_views = db_conn.execute(
|
||||
text("SELECT name FROM sqlite_master WHERE type='view'")
|
||||
).fetchall()
|
||||
for row in query_views:
|
||||
view_name = row[0]
|
||||
db_conn.execute(text(f"DROP VIEW {view_name}"))
|
||||
|
||||
query_indexes = db_conn.execute(
|
||||
text("SELECT name FROM sqlite_master WHERE type='index'")
|
||||
).fetchall()
|
||||
for row in query_indexes:
|
||||
index_name = row[0]
|
||||
db_conn.execute(text(f"DROP INDEX {index_name}"))
|
||||
|
||||
query_triggers = db_conn.execute(
|
||||
text("SELECT name FROM sqlite_master WHERE type='trigger'")
|
||||
).fetchall()
|
||||
for row in query_triggers:
|
||||
trigger_name = row[0]
|
||||
db_conn.execute(text(f"DROP TRIGGER {trigger_name}"))
|
||||
|
||||
|
||||
# endregion
|
0
tests/db/__init__.py
Normal file
0
tests/db/__init__.py
Normal file
0
tests/db/models/__init__.py
Normal file
0
tests/db/models/__init__.py
Normal file
0
tests/db/models/relationships/__init__.py
Normal file
0
tests/db/models/relationships/__init__.py
Normal file
148
tests/db/models/relationships/test_common.py
Normal file
148
tests/db/models/relationships/test_common.py
Normal file
@ -0,0 +1,148 @@
|
||||
"""
|
||||
Database model v5 common relationships
|
||||
|
||||
┌──────┐ ┌──────┐ ┌────────────┐ ┌────────────┐
|
||||
│ Pack ◄───► Song ◄───► Difficulty ◄───┤ PlayResult │
|
||||
└──────┘ └──┬───┘ └─────▲──────┘ └────────────┘
|
||||
│ │
|
||||
│ ┌─────▼─────┐
|
||||
└───────► ChartInfo │
|
||||
└───────────┘
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import (
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
ModelBase,
|
||||
Pack,
|
||||
PlayResult,
|
||||
Song,
|
||||
)
|
||||
|
||||
|
||||
class TestSongRelationships:
|
||||
@staticmethod
|
||||
def init_db(session):
|
||||
ModelBase.metadata.create_all(session.bind)
|
||||
|
||||
def test_relationships(self, db_session):
|
||||
self.init_db(db_session)
|
||||
|
||||
song_id = "test_song"
|
||||
title_en = "Test Lorem Ipsum"
|
||||
artist_en = "Test Artist"
|
||||
|
||||
pack = Pack(
|
||||
id="test_pack",
|
||||
name="Test Pack",
|
||||
description="This is a test pack.",
|
||||
)
|
||||
|
||||
song = Song(
|
||||
idx=1,
|
||||
id=song_id,
|
||||
title=title_en,
|
||||
artist=artist_en,
|
||||
pack_id=pack.id,
|
||||
added_at=datetime(2024, 7, 5, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_pst = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
rating=2,
|
||||
is_rating_plus=False,
|
||||
)
|
||||
chart_info_pst = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
constant=20,
|
||||
notes=200,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_prs = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
rating=7,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
chart_info_prs = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
constant=78,
|
||||
notes=780,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_ftr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
rating=10,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
chart_info_ftr = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
constant=109,
|
||||
notes=1090,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_etr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.ETERNAL,
|
||||
rating=9,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
|
||||
play_result_ftr = PlayResult(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
score=123456,
|
||||
)
|
||||
|
||||
db_session.add_all(
|
||||
[
|
||||
pack,
|
||||
song,
|
||||
difficulty_pst,
|
||||
chart_info_pst,
|
||||
difficulty_prs,
|
||||
chart_info_prs,
|
||||
difficulty_ftr,
|
||||
chart_info_ftr,
|
||||
difficulty_etr,
|
||||
play_result_ftr,
|
||||
]
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
assert pack.songs == [song]
|
||||
|
||||
assert song.pack == pack
|
||||
assert song.difficulties == [
|
||||
difficulty_pst,
|
||||
difficulty_prs,
|
||||
difficulty_ftr,
|
||||
difficulty_etr,
|
||||
]
|
||||
|
||||
assert difficulty_pst.song == song
|
||||
assert difficulty_prs.song == song
|
||||
assert difficulty_ftr.song == song
|
||||
assert difficulty_etr.song == song
|
||||
|
||||
assert difficulty_pst.chart_info_list == [chart_info_pst]
|
||||
assert difficulty_prs.chart_info_list == [chart_info_prs]
|
||||
assert difficulty_ftr.chart_info_list == [chart_info_ftr]
|
||||
assert difficulty_etr.chart_info_list == []
|
||||
|
||||
assert chart_info_pst.difficulty == difficulty_pst
|
||||
assert chart_info_prs.difficulty == difficulty_prs
|
||||
assert chart_info_ftr.difficulty == difficulty_ftr
|
||||
|
||||
# assert play_result_ftr.difficulty == difficulty_ftr
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user