data reimport

This commit is contained in:
Michael Zhang 2023-09-05 20:45:38 -05:00
parent 841a48a955
commit bbdb03e377
7 changed files with 271 additions and 152 deletions

View file

@ -56,8 +56,8 @@ CREATE TABLE `beatmaps` (
`BlacklistReason` TEXT NULL,
`controversy` DECIMAL(10, 8) NULL,
INDEX `Artist`(`DifficultyName`, `Artist`, `Title`),
INDEX `beatmapset_id`(`SetID`),
FULLTEXT INDEX `Artist`(`DifficultyName`, `Artist`, `Title`),
PRIMARY KEY (`BeatmapID`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View file

@ -1,40 +1,44 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex", "fullTextSearch"]
}
datasource db {
provider = "mysql"
url = "mysql://root:example@localhost:3306/omdb"
url = env("DATABASE_URL")
}
model apikeys {
model ApiKey {
ApiID Int @id @default(autoincrement())
Name String? @db.Text
ApiKey String? @unique(map: "ApiKey", length: 255) @db.Text
UserID Int?
@@map("apikeys")
}
model beatmap_creators {
model BeatmapCreator {
BeatmapID Int
CreatorID Int
@@id([BeatmapID, CreatorID])
@@index([BeatmapID], map: "idx_BeatmapID")
@@map("beatmap_creators")
}
model beatmap_edit_requests {
model BeatmapEditRequest {
EditID Int @id @default(autoincrement())
BeatmapID Int?
SetID Int?
UserID Int
EditData Json
Timestamp DateTime @default(now()) @db.Timestamp(0)
Status beatmap_edit_requests_Status? @default(Pending)
Status BeatmapEditRequestStatus? @default(Pending)
EditorID Int?
@@map("beatmap_edit_requests")
}
model beatmaps {
model Beatmap {
BeatmapID Int @id @db.UnsignedMediumInt
SetID Int? @db.UnsignedMediumInt
SetCreatorID Int?
@ -57,34 +61,40 @@ model beatmaps {
BlacklistReason String? @db.Text
controversy Decimal? @db.Decimal(10, 8)
@@index([DifficultyName, Artist, Title], map: "Artist")
@@index([SetID], map: "beatmapset_id")
@@fulltext([DifficultyName, Artist, Title], map: "Artist")
@@map("beatmaps")
}
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model beatmapset_nominators {
model BeatmapSetNominator {
SetID Int?
NominatorID Int?
Mode Int?
@@unique([SetID, NominatorID, Mode], map: "beatmapset_nominators_pk")
@@index([SetID], map: "beatmapset_nominators_SetID_index")
@@map("beatmapset_nominators")
@@ignore
}
model blacklist {
model Blacklist {
UserID Int @id
@@map("blacklist")
}
model comments {
model Comment {
CommentID Int @id @default(autoincrement())
UserID Int
SetID Int
Comment String? @db.Text
date DateTime? @default(now()) @db.Timestamp(0)
@@map("comments")
}
model descriptor_votes {
model DescriptorVote {
VoteID Int @id @default(autoincrement())
BeatmapID Int
UserID Int
@ -93,37 +103,45 @@ model descriptor_votes {
@@unique([BeatmapID, UserID, DescriptorID], map: "descriptor_votes_pk2")
@@index([BeatmapID], map: "descriptor_votes_BeatmapID_index")
@@map("descriptor_votes")
}
model descriptors {
model Descriptor {
DescriptorID Int @id @default(autoincrement())
Name String @unique(map: "descriptors_pk2") @db.VarChar(40)
ShortDescription String? @db.Text
ParentID Int?
Usable Boolean @default(true)
@@map("descriptors")
}
model logs {
model Log {
LogID Int @id @default(autoincrement())
UserID Int
LogData Json?
@@map("logs")
}
model mappernames {
model MapperName {
UserID Int @id
Username String? @db.VarChar(255)
@@map("mappernames")
}
model rating_tags {
model RatingTag {
UserID Int?
BeatmapID Int?
Tag String? @db.VarChar(150)
TagID Int @id @default(autoincrement())
@@unique([BeatmapID, UserID, Tag], map: "rating_tags_pk")
@@map("rating_tags")
}
model ratings {
model Rating {
RatingID Int @id @default(autoincrement())
BeatmapID Int
UserID Int
@ -131,37 +149,41 @@ model ratings {
date DateTime @db.DateTime(0)
@@index([BeatmapID], map: "idx_beatmapID")
@@map("ratings")
}
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model setretrieveinfo {
model SetRetrieveInfo {
LastRetrieval DateTime? @db.DateTime(0)
LastDate DateTime? @db.Date
@@map("setretrieveinfo")
@@ignore
}
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model user_correlations {
model UserCorrelation {
user1_id Int?
user2_id Int?
correlation Float? @db.Float
@@unique([user1_id, user2_id], map: "user_correlations_pk")
@@map("user_correlations")
@@ignore
}
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model user_relations {
model UserRelation {
UserIDFrom Int?
UserIDTo Int?
type Int?
@@unique([UserIDTo, UserIDFrom], map: "user_relations_pk")
@@map("user_relations")
@@ignore
}
model users {
model User {
UserID Int @id
Username String? @db.VarChar(255)
AccessToken String? @db.VarChar(2000)
@ -182,10 +204,14 @@ model users {
Custom50Rating String @default("") @db.VarChar(60)
LastAccessedSite DateTime @default(now()) @db.Timestamp(0)
HideRatings Boolean? @default(false)
@@map("users")
}
enum beatmap_edit_requests_Status {
enum BeatmapEditRequestStatus {
Pending
Denied
Approved
@@map("beatmap_edit_requests_Status")
}

View file

@ -3,18 +3,7 @@ import styles from "./page.module.css";
import { PrismaClient } from "@prisma/client";
import RatingTable from "@/components/RatingTable";
export async function getData() {
const prisma = new PrismaClient();
const comments = await prisma.comments.findMany({ take: 20 });
return { comments };
}
export default async function Home() {
const data = await getData();
console.log("data", data);
return (
<main className={styles.main}>
<div className="flex-container column-when-mobile-container">

View file

@ -0,0 +1,20 @@
.ratingContainer {
background-color: var(--accent-1);
align-items: center;
}
.setImage {
margin-left: 0.5em;
}
.diffThumb {
height: 32px;
width: 32px;
border: 1px solid #ddd;
object-fit: cover;
}
.profilePicture {
width: 24px;
height: 24px;
}

View file

@ -1,20 +1,58 @@
import classNames from "classnames";
import styles from "./RatingTable.module.scss";
import { PrismaClient } from "@prisma/client";
import StarRatingDisplay from "./StarRatingDisplay";
export async function getData() {
const prisma = new PrismaClient();
const ratings = await prisma.ratings.findMany({ take: 20 });
const comments = await prisma.comments.findMany({ take: 20 });
return { comments };
return { ratings, comments };
}
export default async function RatingTable() {
const { ratings} = await getData();
return (
<div
className="flex-child column-when-mobile" // style="width:40%;height:32em;overflow-y:scroll;position:relative;"
>
<div className="flex-container ratingContainer alternating-bg">
{ratings.map((rating) => {
return (
<div className={classNames(styles.ratingContainer)}>
<div className={styles.setImage}>
<a href={`/mapset/${rating.SetID}`}>
<img
src={`https://b.ppy.sh/thumb/${rating.SetID}l.jpg`}
className={styles.diffThumb}
// onerror="this.onerror=null; this.src='/charts/INF.png';"
/>
</a>
</div>
<div>
<a href={`/profile/${rating.UserID}`}>
<img
src={`https://s.ppy.sh/a/${rating.UserID}`}
className={styles.profilePicture}
title="<?php echo GetUserNameFromId($row['UserID'], $conn); ?>"
/>
</a>
</div>
<div className="flex-child" style={{flex:"0 0 66%"}}>
{/* <a style="display:flex;" href="/profile/<?php echo $row["UserID"]; ?>">
<?php echo GetUserNameFromId($row["UserID"], $conn); ?>
</a> */}
<StarRatingDisplay rating={rating.Score} /> on
<a href={`/mapset/${rating.SetID}`}>" . mb_strimwidth(htmlspecialchars($row["DifficultyName"]), 0, 35, "...") . "</a>";
?>
</div>
</div>
);
})}
{/* <div className="flex-container ratingContainer alternating-bg">
<div
className="flex-child" // style="margin-left:0.5em;"
>
@ -62,7 +100,7 @@ export default async function RatingTable() {
</div>{" "}
on <a href="/mapset/115011">Lan</a>{" "}
</div>
</div>
</div> */}
</div>
);
}

View file

@ -0,0 +1,20 @@
.starRatingDisplay {
display: inline-block;
white-space: nowrap;
width: 5em;
padding-right: 0.25em;
}
.starBackground {
color: #203838;
z-index: 0;
display: inline-block;
position: absolute;
}
.starForeground {
color: white;
z-index: 2;
display: inline-block;
position: relative;
}

View file

@ -0,0 +1,26 @@
import { Decimal } from "@prisma/client/runtime/library";
import styles from "./StarRatingDisplay.module.scss";
export interface Props {
rating: Decimal;
}
export default function StarRatingDisplay({ rating }: Props) {
const ratingNumber = rating.toNumber();
const overlay = [0, 1, 2, 3, 4]
.filter((x) => x < ratingNumber)
.map((x) => {
if (ratingNumber - 0.5 === x)
return <i className="star icon-star-half"></i>;
else return <i className="star icon-star"></i>;
});
const backgroundStars = <div className={styles.starBackground}></div>;
return (
<div className={styles.starRatingDisplay}>
{backgroundStars}
<div className={styles.starForeground}>{overlay}</div>
</div>
);
}