添加更新数据

This commit is contained in:
2024-07-29 16:50:07 +08:00
parent d23c5f5c7e
commit 53c71973ae
11 changed files with 398 additions and 189 deletions

View File

@@ -2,18 +2,24 @@ package com.aiosman.riderpro.test
import com.aiosman.riderpro.R
import com.aiosman.riderpro.data.AccountProfile
import com.aiosman.riderpro.data.Comment
import com.aiosman.riderpro.model.MomentItem
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import io.github.serpro69.kfaker.faker
import java.io.File
object TestDatabase {
var momentData = emptyList<MomentItem>()
var accountData = emptyList<AccountProfile>()
var comment = emptyList<Comment>()
var commentIdCounter = 0
var selfId = 1
var imageList = listOf(
"https://img.freepik.com/free-photo/white-billboard-template_23-2147726635.jpg?t=st=1722150015~exp=1722153615~hmac=5540620196d7898215d822be26353c87a63d51bbfb2b814e032626e1948a1583&w=740",
"https://img.freepik.com/free-photo/minimal-clothing-label-fashion-brands_53876-111053.jpg?w=1060&t=st=1722150122~exp=1722150722~hmac=67f8a2b6abfe3d08714cf0cc0085485c3221e1ba00dda14378b03753dce39153",
"https://img.freepik.com/free-photo/marketing-strategy-planning-strategy-concept_53876-42950.jpg",
"https://t4.ftcdn.net/jpg/02/27/00/89/240_F_227008949_5O7yXuEqTwUgs3BGqdcvrNutM5MSxs1t.jpg",
"https://t4.ftcdn.net/jpg/01/86/86/49/240_F_186864971_NixcoDg1zBjjN7soUNhpEVraI4vdzOFD.jpg",
"https://t3.ftcdn.net/jpg/00/84/01/30/240_F_84013057_fsOdzBgskSFUyWyD6YKjIAdtKdBPiKRD.jpg",
"https://t4.ftcdn.net/jpg/00/93/89/23/240_F_93892312_SNyGGruVaWKpJQiVG314gIQmS4EAghdy.jpg",
@@ -32,14 +38,14 @@ object TestDatabase {
"https://t3.ftcdn.net/jpg/02/65/43/04/240_F_265430460_DIHqnrziar7WL2rmW0qbDO07TbxjlPQo.jpg"
)
var followList = emptyList<Pair<Int, Int>>()
var likeCommentList = emptyList<Pair<Int, Int>>()
init {
val faker = faker {
this.fakerConfig {
locale = "en"
}
}
accountData = (0..300).toList().mapIndexed { idx, _ ->
accountData = (0..100).toList().mapIndexed { idx, _ ->
AccountProfile(
id = idx,
followerCount = 0,
@@ -52,7 +58,7 @@ object TestDatabase {
)
}
// make a random follow rel
for (i in 0..10000) {
for (i in 0..500) {
var person1 = accountData.random()
var persion2 = accountData.random()
followList += Pair(person1.id, persion2.id)
@@ -66,11 +72,34 @@ object TestDatabase {
it
}
}
}
momentData = (0..300).toList().mapIndexed { idx, _ ->
momentData = (0..200).toList().mapIndexed { idx, _ ->
val person = accountData.random()
// make fake comment
for (i in 0..faker.random.nextInt(0, 5)) {
commentIdCounter += 1
val commentPerson = accountData.random()
var newComment = Comment(
name = commentPerson.nickName,
comment = "this is comment ${commentIdCounter}",
date = "2023-02-02 11:23",
likes = 0,
replies = emptyList(),
postId = idx,
avatar = commentPerson.avatar,
author = commentPerson.id,
id = commentIdCounter,
liked = false
)
// generate like comment list
for (likeIdx in 0..faker.random.nextInt(0, 5)) {
val likePerson = accountData.random()
likeCommentList += Pair(commentIdCounter, likePerson.id)
newComment = newComment.copy(likes = newComment.likes + 1)
}
comment += newComment
}
MomentItem(
id = idx,
avatar = person.avatar,
@@ -89,4 +118,24 @@ object TestDatabase {
)
}
}
fun updateMomentById(id: Int, momentItem: MomentItem) {
momentData = momentData.map {
if (it.id == id) {
momentItem
} else {
it
}
}
}
fun saveResultToJsonFile() {
val gson: Gson = GsonBuilder().setPrettyPrinting().create()
// save accountData to json file
File("accountData.json").writeText(accountData.toString())
// save momentData to json file
// save comment to json file
}
}