推分计划设计

This commit is contained in:
2025-05-12 18:29:07 +08:00
parent 633d9d4705
commit e141fac69b
4 changed files with 83 additions and 38 deletions

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">

View File

@@ -11,7 +11,7 @@ android {
minSdk 29 minSdk 29
targetSdk 34 targetSdk 34
versionCode 1 versionCode 1
versionName "1.6.4 beta" versionName "1.6.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@@ -60,14 +60,14 @@ public class MusicFragment extends Fragment {
private RecyclerView recyclerView; private RecyclerView recyclerView;
private MusicRatingAdapter adapter; private MusicRatingAdapter adapter;
private SuggestMusicRatingAdapter adapterSuggest; private SuggestMusicRatingAdapter adapterSuggest;
private DataAnalyzer dataAnalyzer;
private List<UserMusicList> musicSongsRatings; private List<UserMusicList> musicSongsRatings;
private List<MusicRating> musicRatings = new ArrayList<>(); private List<MusicRating> musicRatings = new ArrayList<>();
private String userId; private String userId;
private int iconId; private int iconId;
private String username; private String username;
private static Map<Integer, Song> songs = new HashMap<>(); private static Map<Integer, Song> songs = new HashMap<>();
private Map<String, Song> loadedSongs;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -430,7 +430,7 @@ public class MusicFragment extends Fragment {
private void showOptionsDialog() { private void showOptionsDialog() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.CustomDialogStyle); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.CustomDialogStyle);
builder.setTitle("选项"); builder.setTitle("选项");
builder.setItems(new CharSequence[]{"更新数据", "分数排序", "搜索指定歌曲"}, (dialog, which) -> { builder.setItems(new CharSequence[]{"更新数据", "分数排序", "搜索指定歌曲","推分安排"}, (dialog, which) -> {
switch (which) { switch (which) {
case 0: case 0:
// 更新数据 // 更新数据
@@ -459,11 +459,18 @@ public class MusicFragment extends Fragment {
// 搜索指定歌曲 // 搜索指定歌曲
showSearchDialog(); showSearchDialog();
break; break;
case 3:
//推分安排
setRatingProject();
} }
}); });
builder.show(); builder.show();
} }
private void setRatingProject() {
}
private void sortMusicRatingsByRating() { private void sortMusicRatingsByRating() {
Collections.sort(musicRatings, new Comparator<MusicRating>() { Collections.sort(musicRatings, new Comparator<MusicRating>() {
@Override @Override
@@ -502,10 +509,10 @@ public class MusicFragment extends Fragment {
private void dataanlysis() { private void dataanlysis() {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper()); Handler handler = new Handler(Looper.getMainLooper());
TextView au = binding.an;
executor.execute(() -> { executor.execute(() -> {
// Perform data processing in the background // Perform data processing in the background
DataAnalyzer dataAnalyzer = new DataAnalyzer(); dataAnalyzer = new DataAnalyzer();
try { try {
@@ -516,9 +523,6 @@ public class MusicFragment extends Fragment {
inputStream.close(); inputStream.close();
String json = new String(buffer, StandardCharsets.UTF_8); String json = new String(buffer, StandardCharsets.UTF_8);
dataAnalyzer = new Gson().fromJson(json,DataAnalyzer.class); dataAnalyzer = new Gson().fromJson(json,DataAnalyzer.class);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -530,7 +534,7 @@ public class MusicFragment extends Fragment {
inputStream.close(); inputStream.close();
String json = new String(buffer, StandardCharsets.UTF_8); String json = new String(buffer, StandardCharsets.UTF_8);
Type type = new TypeToken<Map<String, Song>>() {}.getType(); Type type = new TypeToken<Map<String, Song>>() {}.getType();
Map<String, Song> loadedSongs = new Gson().fromJson(json, type); loadedSongs = new Gson().fromJson(json, type);
// 手动转换 key 为 Integer 并放入全局 map // 手动转换 key 为 Integer 并放入全局 map
for (Map.Entry<String, Song> entry : loadedSongs.entrySet()) { for (Map.Entry<String, Song> entry : loadedSongs.entrySet()) {
@@ -548,16 +552,16 @@ public class MusicFragment extends Fragment {
List<MusicRating> b100 = musicRatings.subList(50, 100); List<MusicRating> b100 = musicRatings.subList(50, 100);
List<Integer> ids= new ArrayList<>(); List<Integer> ids= new ArrayList<>();
int worstRating = b50.get(b50.size() - 1).getRating(); int worstRating = b50.get(b50.size() - 1).getRating();
int bestRating = b50.get(0).getRating();
List<MusicRating> suggestMusicRatingList = new ArrayList<>(); List<MusicRating> suggestMusicRatingList = new ArrayList<>();
for (int x = 0; x < 50; x++) { for (int x = 0; x < 50; x++) {
total += b50.get(x).getRating(); total += b50.get(x).getRating();
MusicRating m = b100.get(x); MusicRating m = b100.get(x);
int nowache = m.getAchievement(); int nowache = m.getAchievement();
int target = 0; int target = 0;
if (nowache >= 1000000 && nowache < 10050000) { if (nowache >= 1000000 && nowache < 1005000) {
target = 1005001; target = 1005001;
} else if (nowache >= 995000 && nowache < 10000000) { } else if (nowache >= 995000 && nowache < 1000000) {
target = 1000001; target = 1000001;
} else if (nowache >= 990000 && nowache < 995000) { } else if (nowache >= 990000 && nowache < 995000) {
target = 995001; target = 995001;
@@ -579,6 +583,38 @@ public class MusicFragment extends Fragment {
suggestMusicRatingList.add(m); suggestMusicRatingList.add(m);
} }
} }
for (int x = 0; x < 50; x++) {
MusicRating m = b50.get(x);
if (m.getLevel_info() > ((double) (total - 1000) / 1000)) {
continue;
}
int nowache = m.getAchievement();
int target = 0;
if (nowache >= 1000000 && nowache < 1005000) {
target = 1005001;
} else if (nowache >= 995000 && nowache < 1000000) {
target = 1000001;
} else if (nowache >= 990000 && nowache < 995000) {
target = 995001;
} else if (nowache >= 980000 && nowache < 990000) {
target = 990001;
} else if (nowache >= 970000 && nowache < 980000) {
target = 980001;
}
double b1 = (double) target / 10000;
int targetRating = getRatingChart(m.getLevel_info(), b1);
if (targetRating > worstRating) {
m.setExtNum1(target);
if (m.getMusicId() > 10000) {
ids.add(m.getMusicId()-10000);
}else {
ids.add(m.getMusicId());
}
m.setExtNum2(targetRating);
suggestMusicRatingList.add(m);
}
}
List<EasySong> easySongs = new ArrayList<>(); List<EasySong> easySongs = new ArrayList<>();
//看看别人打什么 //看看别人打什么
Log.d("TOP",total + ""); Log.d("TOP",total + "");
@@ -599,30 +635,31 @@ public class MusicFragment extends Fragment {
}else if (total>=11000) { }else if (total>=11000) {
easySongs = dataAnalyzer.getEasySongs().get("11000"); easySongs = dataAnalyzer.getEasySongs().get("11000");
} }
for (int x = 0 ; x < easySongs.size();x ++) { if (easySongs != null) {
EasySong e = easySongs.get(x); for (EasySong e : easySongs) {
if (e.getPercent()>0.1) { if (e.getPercent() > 0.1) {
if (ids.contains(e.getId())) { if (ids.contains(e.getId())) {
continue; continue;
} }
; ;
double diff = songs.get(e.getId()).getDifficulties().get(e.getType())[e.getLevel()].getLevel_value(); double diff = Objects.requireNonNull(Objects.requireNonNull(songs.get(e.getId())).getDifficulties().get(e.getType()))[e.getLevel()].getLevel_value();
double b = 99.0000; double b = 99.0000;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
b = b + 0.5 * (i - 1); b = b + 0.5 * (i - 1);
int ra = getRatingChart(diff, b); int ra = getRatingChart(diff, b);
if (ra > worstRating) { if (ra > worstRating) {
MusicRating musicRating = new MusicRating(); MusicRating musicRating = new MusicRating();
musicRating.setMusicId(e.getId()); musicRating.setMusicId(e.getId());
musicRating.setMusicName(e.getTitle()); musicRating.setMusicName(e.getTitle());
musicRating.setExtNum1((int)(b*10000)); musicRating.setExtNum1((int) (b * 10000));
musicRating.setExtNum2(ra); musicRating.setExtNum2(ra);
musicRating.setRating(0); musicRating.setRating(0);
musicRating.setAchievement(0); musicRating.setAchievement(0);
musicRating.setLevel_info(diff); musicRating.setLevel_info(diff);
musicRating.setType(e.getType()); musicRating.setType(e.getType());
suggestMusicRatingList.add(musicRating); suggestMusicRatingList.add(musicRating);
break; break;
}
} }
} }
} }
@@ -630,10 +667,13 @@ public class MusicFragment extends Fragment {
// Update UI on the main thread // Update UI on the main thread
int finalTotal = total;
handler.post(() -> { handler.post(() -> {
RecyclerView suggest = binding.getRoot().findViewById(R.id.suggestion); RecyclerView suggest = binding.getRoot().findViewById(R.id.suggestion);
suggest.setLayoutManager(new GridLayoutManager(getContext(), 1)); suggest.setLayoutManager(new GridLayoutManager(getContext(), 1));
au.setText("Rating分析:最低分 " + worstRating + "分,最高分 " + bestRating + ",平均分" + (finalTotal / 50) + "");
adapterSuggest = new SuggestMusicRatingAdapter(suggestMusicRatingList); adapterSuggest = new SuggestMusicRatingAdapter(suggestMusicRatingList);
suggest.setAdapter(adapterSuggest); suggest.setAdapter(adapterSuggest);
adapterSuggest.notifyDataSetChanged(); adapterSuggest.notifyDataSetChanged();

View File

@@ -104,6 +104,12 @@
android:padding="8dp" android:padding="8dp"
android:id="@+id/su" android:id="@+id/su"
android:textSize="18sp"/> android:textSize="18sp"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
android:textColor="@color/textcolorPrimary"
android:text="⭐分析"
android:padding="8dp"
android:id="@+id/an"
android:textSize="13sp"/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/suggestion" android:id="@+id/suggestion"
android:layout_width="match_parent" android:layout_width="match_parent"