Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复同步keep数据出现的错误 #20

Merged
merged 4 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ db.csv
danpalmer.sql

.mypy_cache

.vscode
4 changes: 2 additions & 2 deletions scripts/keep_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_raw_data_to_nametuple(run_data, old_gpx_ids, with_download_gpx=False):
keep_id = run_data["id"].split("_")[1]

start_time = run_data["startTime"]
if run_data.get("vendor").get("genre", "") == "KeepApp":
if run_data.get("vendor").get("genre", "") == "KeepApp" and run_data.get("rawDataURL") != '':
raw_data_url = run_data.get("rawDataURL")
r = requests.get(raw_data_url)
# string strart with `H4sIAAAAAAAA` --> decode and unzip
Expand Down Expand Up @@ -171,7 +171,7 @@ def parse_points_to_gpx(run_points_data, start_time):
{
"latitude": point["latitude"],
"longitude": point["longitude"],
"elevation": point["verticalAccuracy"],
"elevation": point["verticalAccuracy"] if "verticalAccuracy" in point.keys() else None,
Copy link
Owner

@yihong0618 yihong0618 Oct 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to get if verticalAccuracy attr first.
if there is no value here
We do not add it to the dict.
only keep the latitude, longitude, time in the dict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other props may not need to be judged to exist.

   # future to support heart rate
    points_dict_list = []
    for point in run_points_data:
        points_dict = {
            "latitude": point["latitude"],
            "longitude": point["longitude"],
            "time": datetime.utcfromtimestamp((point["timestamp"] * 100 + start_time) / 1000),
        }
        if "verticalAccuracy" in point.keys():
            points_dict["verticalAccuracy"] = point["verticalAccuracy"]
        points_dict_list.append(points_dict)
    gpx = gpxpy.gpx.GPX()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. only in is fine
    image
  2. points_dict["elevation"] = point["verticalAccuracy"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll pr again.

"time": datetime.utcfromtimestamp((point["timestamp"] * 100 + start_time) / 1000),
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const scrollToMap = () => {
const locationForRun = (run) => {
const location = run.location_country;
let [city, province, country] = ['', '', ''];
if (location) {
if (location && location != "None") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest add if here, and we do not need to compare with the location string

    const countryMatch = l[l.length - 1].match(/[\u4e00-\u9fa5].*[\u4e00-\u9fa5]/) || l[2].match(/[\u4e00-\u9fa5].*[\u4e00-\u9fa5]/);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length of the l variable may be equal to 1, so add the logic to judge the length.

const location = run.location_country;
  let [city, province, country] = ['', '', ''];
  if (location) {
    // Only for Chinese now
    const cityMatch = location.match(/[\u4e00-\u9fa5]*市/);
    const provinceMatch = location.match(/[\u4e00-\u9fa5]*省/);
    if (cityMatch) {
      [city] = cityMatch;
    }
    if (provinceMatch) {
      [province] = provinceMatch;
    }
    const l = location.split(',');
    // or to handle keep location format
    let countryMatch = l[l.length - 1].match(/[\u4e00-\u9fa5].*[\u4e00-\u9fa5]/);
    if (!countryMatch && l.length >= 3) {
      countryMatch = l[2].match(/[\u4e00-\u9fa5].*[\u4e00-\u9fa5]/);
    }
    if (countryMatch) {
      [country] = countryMatch;
    }
  }

// Only for Chinese now
const cityMatch = location.match(/[\u4e00-\u9fa5]*市/);
const provinceMatch = location.match(/[\u4e00-\u9fa5]*省/);
Expand Down