Skip to content

Commit f00606e

Browse files
add splits
1 parent 66e7821 commit f00606e

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: L10N output mapping splits
3+
4+
run-name: ${{ github.actor }} is writing L10N mapping splits
5+
on:
6+
schedule:
7+
- cron: "0 0 * * 1"
8+
9+
permissions:
10+
contents: "write"
11+
12+
jobs:
13+
Select-Channels:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
channels: ${{ steps.splits.outputs.channels }}
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
- name: Select test channels
21+
id: splits
22+
run: |
23+
python3 choose_l10n_beta_split.py

choose_l10n_beta_split.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
import logging
3+
import sys
4+
from collections import defaultdict
5+
6+
from choose_l10n_ci_set import valid_l10n_mappings
7+
8+
9+
def distribute_mappings_evenly(mappings):
10+
"""
11+
Distribute the selected mappings into 3 splits and return the container.
12+
13+
Args:
14+
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
15+
"""
16+
if not mappings:
17+
return {}
18+
# sort the mappings by the length of the regions per site
19+
mappings = dict(sorted(mappings.items(), key=lambda val: len(val[1]), reverse=True))
20+
# place the mappings into 3 containers evenly according to the load
21+
loads = [0, 0, 0]
22+
balanced_splits = [defaultdict(list) for _ in range(3)]
23+
for site, regions in mappings.items():
24+
min_idx = loads.index(min(loads))
25+
balanced_splits[min_idx][site] = list(regions)
26+
loads[min_idx] += len(regions)
27+
return balanced_splits
28+
29+
30+
if __name__ == "__main__":
31+
l10n_mappings = valid_l10n_mappings()
32+
all_splits = distribute_mappings_evenly(l10n_mappings)
33+
if not all_splits:
34+
logging.warning("No valid l10n mappings")
35+
sys.exit(1)
36+
for idx, split in enumerate(all_splits, start=1):
37+
with open(f"l10n_CM/beta_run_splits/l10n_split_{idx}.json", "w") as f:
38+
json.dump(split, f)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"demo": ["US", "GB", "DE", "FR", "PL", "ES", "CA"], "bijoubrigitte": ["DE"], "calvinklein": ["US"], "aldoshoes": ["US"], "peacocks": ["GB"], "assos": ["GB"], "fnac": ["FR"], "canadatire": ["CA"]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"amazon": ["US", "CA", "DE", "FR"], "walmart": ["US", "CA"], "mediamarkt": ["DE"], "zalando": ["PL"], "bestbuy": ["US"], "apple": ["US"], "whittard": ["GB"], "tiffany": ["IT"], "yellowkorner": ["FR"], "burtsbees": ["CA"]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"ebay": ["ES", "IT", "CA", "GB"], "etsy": ["US", "CA"], "justspices": ["DE"], "lowes": ["US"], "newegg": ["US"], "wish": ["US"], "diy": ["GB"], "artsper": ["FR"], "newbalance": ["CA"]}

modules/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ def __init__(self):
104104
"Yukon": "YT",
105105
}
106106
# temporary fix until faker issue is resolved
107-
self.country_local_translation = {"Germany": "Deutschland", "Italy": "Italia", "Spain": "España"}
107+
self.country_local_translation = {
108+
"Germany": "Deutschland",
109+
"Italy": "Italia",
110+
"Spain": "España",
111+
}
108112
self.fake = None
109113
self.locale = None
110114

@@ -557,7 +561,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
557561
"GB": "44",
558562
"IT": "39",
559563
"PL": "48",
560-
"ES": "34"
564+
"ES": "34",
561565
}
562566

563567
# Sub out anything that matches this regex statement with an empty string to get rid of extensions in generated phone numbers

0 commit comments

Comments
 (0)