Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
- screens type error
-  when first imported, the time_zone value is None
  • Loading branch information
cntvc committed Aug 26, 2024
1 parent 86142d0 commit 0abf5b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
67 changes: 35 additions & 32 deletions star_rail/module/record/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,17 @@ async def refresh_gacha_record(self, source: typing.Literal["webcache", "clipboa
return cnt

next_batch_id = await record_repository.get_next_batch_id()
latest_batch_record = await record_repository.get_latest_batch()
timezone = latest_batch_record.region_time_zone
target_time_zone = region_time_zone
if latest_batch_record := await record_repository.get_latest_batch():
target_time_zone = latest_batch_record.region_time_zone

def convert_timezone(data: list[GachaRecordItem], from_tz: int, target_tz: int):
if from_tz == target_tz:
return
for item in data:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)

convert_timezone(need_insert, region_time_zone, timezone)
_convert_record_timezone(need_insert, region_time_zone, target_time_zone)

info = GachaRecordArchiveInfo(
uid=self.user.uid,
batch_id=next_batch_id,
lang=lang,
region_time_zone=timezone,
region_time_zone=target_time_zone,
source=f"{APP_NAME}_{version}",
)
cnt = await record_repository.insert_gacha_record(need_insert, info)
Expand Down Expand Up @@ -414,22 +409,13 @@ async def _handle_srgf_data(self, srgf_data: srgf.SRGFData, timezone: int):
record_repository = GachaRecordRepository(self.user)
next_batch_id = await record_repository.get_next_batch_id()

def convert_timezone(data: srgf.SRGFData, target_tz: int):
if data.info.region_time_zone == target_tz:
return
from_tz = data.info.region_time_zone
for item in data.list:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)
data.info.region_time_zone = target_tz
return

target_region_timezone = timezone
if next_batch_id > 1:
# 时区与第一个记录保持一致
latest_batch_record = await record_repository.get_latest_batch()
target_region_timezone = latest_batch_record.region_time_zone

convert_timezone(srgf_data, target_region_timezone)
_convert_srgf_timezone(srgf_data, target_region_timezone)

item_list, srgf_info = srgf.convert_to_gacha_record_data(srgf_data)
if srgf_info.lang not in ["zh-cn", "en-us"]:
Expand Down Expand Up @@ -463,23 +449,13 @@ async def _handle_uigf_data(self, uigf_data: uigf.UIGFModel, timezone: int):
record_repository = GachaRecordRepository(self.user)
next_batch_id = await record_repository.get_next_batch_id()

def convert_timezone(data: uigf.UIGFModel, target_tz: int):
_record = data.hkrpg[0]
if _record.timezone == target_tz:
return

from_tz = _record.timezone
for item in _record.list:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)
_record.timezone = target_tz
return

target_region_timezone = timezone
if next_batch_id > 1:
# 时区与第一个记录保持一致
latest_batch_record = await record_repository.get_latest_batch()
target_region_timezone = latest_batch_record.region_time_zone
convert_timezone(uigf_data, target_region_timezone)

_convert_uigf_timezone(uigf_data, target_region_timezone)

if record not in ["zh-cn", "en-us"]:
record.lang = settings.METADATA_LANG
Expand Down Expand Up @@ -578,3 +554,30 @@ async def import_gacha_record(self):
async def display_analysis_results(self):
analyzer = GachaRecordAnalyzer(self.user)
return await analyzer.load_analyze_result()


def _convert_record_timezone(data: list[GachaRecordItem], from_tz: int, target_tz: int):
if from_tz == target_tz:
return
for item in data:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)


def _convert_srgf_timezone(data: srgf.SRGFData, target_tz: int):
if data.info.region_time_zone == target_tz:
return
from_tz = data.info.region_time_zone
for item in data.list:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)
data.info.region_time_zone = target_tz


def _convert_uigf_timezone(data: uigf.UIGFModel, target_tz: int):
_record = data.hkrpg[0]
if _record.timezone == target_tz:
return

from_tz = _record.timezone
for item in _record.list:
item.time = Date.convert_timezone(item.time, from_tz, target_tz)
_record.timezone = target_tz
2 changes: 1 addition & 1 deletion star_rail/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HSRApp(App):
]

SCREENS = {
"create_account_screen": CreateAccountScreen(),
"create_account_screen": CreateAccountScreen,
}
client: HSRClient

Expand Down

0 comments on commit 0abf5b1

Please sign in to comment.