← back to Dw Kravet Hires

scripts/__pycache__/build-batchC-map.cpython-314.pyc

146 lines

+
�)�j�;��\�Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIHt	^RI
Ht^RIH
t
Ht^RIHtHt^RIHt]P(P+]P(P-]44t]P(P+]4t]P(P5]R4t]P(P5]R4t]P(P5]R4t]P(P5]R	4t]P(P5]R
4t]P(P5]R4t ]!!]PDPGRR
44t$]!!]PDPGRR44t%Rt&Rt'Rt(Rt)Rt*Rt+Rt,Rt-Rt.Rt/Rt0Rt1Rt2]3R8Xd
]2!4R#R#)uATK-12097 Batch C — Hollywood Wallcoverings hi-res featured-image swap map.

Hollywood Wallcoverings is a PRIVATE LABEL of Momentum/Versa. Hi-res source =
the momentum_colorways staging table's Cloudinary image_url, which is served with
a downscale transform (.../image/upload/c_scale,w_640/v1/hi_res/<file>). We build
the hi-res candidate by REWRITING c_scale,w_640 -> c_scale,w_2000 (bigger). No leak
risk: apply-hires uses the hi-res URL only as `originalSource`, so Shopify downloads
and RE-HOSTS the image on its own CDN — the momentum cloudinary domain never appears
on the storefront.

JOIN: shopify_products.dw_sku <-> momentum_colorways.dw_sku is EMPTY (Shopify carries
the real X-codes; momentum staging carries fabricated DWHD-* codes). So the join used
is the manufacturer-code join: shopify mfr_sku tail (code after last '_') = momentum
alt_sku OR pattern_sku, requiring a UNIQUE resulting image (the vendor code encodes
pattern+colorway, so a unique code match is colorway-level authoritative). Ambiguous
(>1 distinct image) rows are held to tier2-colorway-unverified.

Input : data/tk12097/batchC-candidates.tsv
        shopify_id       mfr_sku         dw_sku          cur_url         momentum_raw_url        join_type
Output: data/tk12097/batchC-final-map.json    (apply-hires.mjs row schema + counts)
        data/tk12097/batchC-measured.json      (full per-row measurement evidence)
        data/tk12097/batchC-tier2-colorway-unverified.json
        data/tk12097/batchC-no-hires-source.json

All $0, network reads only; every dimension MEASURED (ranged-GET + PIL), never claimed.
N)�Counter)�Request�urlopen)�	HTTPError�URLError)�Imagezdata/tk12097zbatchC-candidates.tsvzbatchC-final-map.jsonzbatchC-measured.jsonz%batchC-tier2-colorway-unverified.jsonzbatchC-no-hires-source.json�
MAX_LOWRES�500�HIRES_FLOOR�800i�z*Mozilla/5.0 (dw-preflight TK-12097 batchC)c�2�VPR4^,#)�?)�split)�urls&�F/Users/macstudio3/Projects/dw-kravet-hires/scripts/build-batchC-map.py�strip_qsr2s���9�9�S�>�!���c���\V4pRV9dVPRR4#\P!RV4pV'd/VP	^4R,VP	^4,#R#)zGRewrite the momentum cloudinary downscale transform to w_2000 (bigger).z
c_scale,w_640zc_scale,w_2000�6^(https?://[^/]+/image/upload/)(.+?)(/v\d+/hi_res/.+)$N)r�replace�re�match�group��raw�u�ms&  r�
rewrite_w2000r6s]����
�A��!���y�y��*:�;�;�
���J�A�N�A���w�w�q�z�,�,�q�w�w�q�z�9�9�rc���\V4p\P!RV4pV'd7VP^4VP^4P	R4,#R#)z<Remove the transform segment entirely -> the original asset.r�/N)rrrr�lstriprs&  r�strip_transformr!BsH����
�A�
���J�A�N�A���w�w�q�z�A�G�G�A�J�-�-�c�2�2�2�rc��\V4p\P!RV4'd\P!RRV4#\P!RV4pV'd/VP^4R,VP^4,#\P!RV4pV'd/VP^4R,VP^4,#R#)z2Cap an oversized candidate to w_5000 (re-measure).z
c_scale,w_\d+zc_scale,w_5000z1^(https?://[^/]+/image/upload/)(/v\d+/hi_res/.+)$rN)rr�search�subrr)rrr�m2s&   r�	cap_w5000r&Ks�����
�A�	�y�y�!�1�%�%��v�v�&�(8�!�<�<�
���E�q�I�A���w�w�q�z�,�,�q�w�w�q�z�9�9�	���K�Q�	O�B�	��x�x��{�-�-������;�;�rc	�\�\VR\RRV^,
2/R7p\V^-R7;_uu_4pVPpVPPRR4pRpRV9dIVP
R^4^,P4pVP4'd\V4pVfLVPPR	4pV^�8Xd*V'd"VP4'd\V4pVP4p	RRR4XXX	3# +'giL;i)
z
User-Agent�Rangezbytes=0-)�headers)�timeoutz
Content-Range�NrzContent-Length)r�UAr�statusr)�get�rsplit�strip�isdigit�int�read)
r�nbytes�req�r�code�cr�total�tail�cl�datas
&&        r�fetch_head_bytesr=Ys���
�#��b�'�X�f�Q�h�Z�;P�Q�
R�C�	��b�	!�	!�Q��x�x��
�Y�Y�]�]�?�B�
/�����"�9��9�9�S�!�$�Q�'�-�-�/�D��|�|�~�~��D�	���=������/�0�B��s�{�r�b�j�j�l�l��B����v�v�x��
"������
"�	!�s�A.D�$8D�D�3D�D+	c�l�RV/p\VR4wr#pRpRFspV\V48�d\W4wrxpV'dTp\P!\P
!V44q�P
RR4V	PpM	TPY#V'd
V^,MRV'd
V^,MRR7VR9dVPRV2RR7V#VfVPRRR7V#\V4VR&VPR	R
R7V# \dEKi;i \d7p
TPT
PRT
P2RR7Rp
?
T#Rp
?
i\\3d0p
TPRR\T
4R
,R7Rp
?
T#Rp
?
ii;i)r�N)�http�
meas_bytes�meas_w�meas_h�HTTP_F)r-�ok�NO_DIMS�meas_le�OKT)r@r-rE�ERR:N�N)r-rE�err)r?ii)����)r=�lenr�open�io�BytesIO�draft�size�	Exception�update�maxrr7r�str)r�resr7r9r<�dims�rng�code2�total2�im�es&          r�measure_urlr_ks����#�,�C�=�,�S�%�8���T���+�C�	
���T��?�*:�3�*D�'�E�4�� &���Z�Z��
�
�4� 0�1��8�8�D�$�3G��w�w���,�	�
�
��&*�4��7��&*�4��7��	�	7��z�!��J�J��d�V�n��J�7����<��J�J�i�E�J�2�3�J��T���I���
�
�$�4�
�(�
�J���
��
���C��
�
�����q�v�v�h�'7�E�
�B�B��J��
�i� �=��
�
�%�E�s�1�v�d�|�
�<�<��J��=�s_�D4�A/D!�)D4�6.D4�%D4�>!D4�!D1�,D4�0D1�1D4�4F3�?+E0�0F3�F3�$F.�.F3c���.p\\4;_uu_4pVF�pVPR4pV'gKVPR4p\	V4^8dKATPRV^,RV^,;'gRRV^,;'gRRV^,;'gRRV^,;'gRRV^,/4K�	RRR4V# +'giT#;i)	�
�	�
shopify_id�mfr_skuN�dw_sku�current_url�momentum_raw�	join_type)rO�SRC�rstriprrN�append)�rows�f�line�ps    r�load_candidatesrp�s���
�D�	
�c���a��D��;�;�t�$�D����
�
�4� �A��1�v��z���K�K��q��t�Y��!�����!�1�Q�4�<�<�4���!�����'��1�����{�A�a�D�J�
K��
��K�
���K�s$�A(C�C�C�)C�<C�C,	c��VPR4'd\VR,4MRRRR/pWR&VPR4VR&V#)rfrEFr-�
NO_CUR_URL�cur_measurerG�cur_le)r.r_)r6rs& r�measure_currentru�sK��)*���}�)=�)=��A�m�$�%�D�%�QY�[g�Ch�A��m���%�%�	�"�A�h�K��Hrc�$a�VPR4pV'g
RVR&RVR&V#VPR4;'g^o\V4pRp.pV'dU\V4qTPRV34VPR4'd!RVR	VR
,RVPR4R
R/pV3RlpV!V4'g�\	V4pV'd�\V4q�PRV34VPR4'dTRVR	VR
,RVPR4R
R/p	V!V	4'd&V!V4'dV	R	,VR	,8�dT	pVU
Uu.uFwr�R
V
/VCNK
	upp
VR&V'dV!V4'g'V'd
VR	,MRpRSRVR2VR&RVR&V#VR	,\
8�g#VR,'EdVR,\8�d�\VR
,R8Xd
VR,MT4p
V
'd�\V
4q�VR&VPR4'd}VR
,\
8:dkVPR4'dVR,\8�gBVR
,S8�d4VR
,\8�d"W�R&VR
,VR&RVR&RVR&RVR&V#RVPRR4,VR&RVR&V#VR,VR&VR	,VR&RVR&VR
,VR&RVR&RVR&V#uupp
i)rg�NO_MOMENTUM_SOURCE�hires_statusFrErtN�w2000r�lerG�bytesrA�variantc�`<�T;'d%VR,S8�;'dVR,\8�#)rz)r
)�crts&�r�genuine�measure_hires.<locals>.genuine�s+����@�@�Q�t�W�v�%�@�@�!�D�'�[�*@�@r�orig�hires_trieszNO_UPGRADE(cur=z,best=�)�capped_measure�	final_url�final_leT�capped�PASS_CAPPEDzSTILL_OVER_AFTER_CAP:r-r
�
hires_variant�PASS)	r.rr_rkr!�SHOP_PX�
SHOP_BYTESr&r
)r6r�c2000�chosen�triesrrr��mo�cand�v�mm�bestr��mcrts&              @r�
measure_hiresr��s����
�%�%��
�C��0��.��E�!�D�'�!�8�
�U�U�8�_�
!�
!��F��#��E�
�F��E��������g�q�\� :��5�5��;�;��U�D�!�I�,�����|�AT�V_�ah�i�F�A��6�?�?��s�#����T�"�B�L�L�&�"��$>��v�v�d�|�|��t�T�2�i�=�'�2�6�6�,�CW�Yb�dj�k���4�=�=�'�&�/�/�T�$�Z�&�QU�,�=V�!�F�:?�@�%����A�,��,�%�@�A�m�������%�v�d�|�4��-�f�X�V�D�6��C��.��u�Q�t�W�]^�V^�
�d�|�g��&��/�/�f�W�o�
�6R��F�9�,=��,G�6�%�=�S�Q����V�$�B�a�(8�&9��v�v�d�|�|��9�
�� 8�"�&�&��BV�BV�[]�^j�[k�nx�[x��i�=�6�)�b��m�{�.J�%+�k�N�R�	�]�Q�z�]�Z^�A�h�K�(5�A�n�%��q��w�a�x� 7�"�&�&��3�:O� O�A�n��[`�QR�SW�QX�ij�bj��E�]�A�k�N�F�4�L�A�j�M�PU�!�H�+��	�*�A�o���A�n��$��$���H��#As� Lc �aa�\4p\V4p\RVR2\PR7\
P!^R7;_uu_4p\VP\V4^4F6wr4VR,^8XgK\RVRV2\PR7K8	RRR4VUu.uFqUR,eKVNK	ppVUu.uF%qUR,fKVR,\8:gK#VNK'	ppVUu.uF%qUR,fKVR,\8�gK#VNK'	pp\R	\R
\V4R\V4R\V42\PR7VUu.uF-qUPR
4'gKVR,R8XgK+VNK/	p	p\V	4p
\RV
2\PR7\
P!^R7;_uu_4p\VP\V	4^4F6wr4V^�,^8XgK\RVRV
2\PR7K8	RRR4V	Uu.uFqUPR4'gKVNK	ppV	Uu.uFqUPR4'dKVNK	pp.p
VF^pVR,R8XgKV
PRVR,RRRVR,RVR,RVR,RVR,R
VR
,RR/4K`	VUu.uF+qUPR
4'dVR,R8XgK)VNK-	pp.oVF�pSPRVR,RRRVR,RVR,RVR,RVR,RVR,R VR!,R"VR#,R$R%R&\VPR'44R(TPR(VPR'4'gR)MR'4R*R+/
4K�	V3R,lpR-V!R.R/4R0V!R/R14R2V!R1R34R4V!R3R54R6\R7S44/p/pRqFo\V3R8lS44VR9S2&K 	\!\#R:V444pR;VR<\V4R=\V4R>\V4R?V
R@\V4RA\V4RBVRC\V
4RD\V4RE\S4RF\RGS44RHR\S4/RIVRJV/pRKRLRMRNRORPRQ\$P$P'4P)4RR,RSRTRURVRRRWRXRYRZR[R\\*R]2R^R_R`VRaS/
p\,P.!V\1\2Rb4^Rc7\,P.!RKRLRMRNRd\$P$P'4P)4RR,Re\Rf\*RaV/\1\4Rb4^Rc7\,P.!RaV
/\1\6Rb4^Rc7\,P.!V\1\8Rb4^Rc7\\,P:!V^Rc74V'dLVUu.uFqUR#,NK
	pp\Rg\=V4Rh\?V4Ri2\PR7\Rj\PR7VRk,FXp\RlVR,RmVR,RnVR#,RoVPR(4RpVR!,2
\PR7KZ	R# +'giEL�;iuupiuupiuupiuupi +'giEL;iuupiuupiuupiuupi)rzloaded z active Hollywood candidates)�file)�max_workersi�z  phase1 measured rNrtz  phase1: lowres(<= zpx)=z already-hi=z cur-unreachable=rgrh�code_uniquez:  phase2 candidates (lowres w/ code_unique momentum src): z  phase2 measured rE�	ambiguousrc�vendorzHollywood Wallcoveringsrdre�	cur_width�rollback_urlrf�reason�'ambiguous_code_multiple_distinct_images�none�current_400px_url�proposed_hires_urlr��hires_ler��hires_source�momentum_colorways_cloudinary�preflight_cappedr�r�ry�swappable_from_local_stagingTc�4<aa�\VV3RlS44#)c3�`<"�TF#pSVR,u;8:d
S8gKMK^x�K%	R#5i�r�N�)�.0r6�hi�los& ��r�	<genexpr>�%main.<locals>.band.<locals>.<genexpr>
s&����C�h��"��*�
�*B��*B�1�*B�1�h�s�.�.�
.)�sum)r�r��map_rowssff�r�band�main.<locals>.band	s����C�h�C�C�Crz500-800��� z800-1200�z	1200-2000i�z	2000-3500�
z3500+c3�D"�TFqR,R8�gK^x�K	R#5i)r�r�Nr��r�r6s& rr��main.<locals>.<genexpr>s���B��1�j�M�T�,A�Q�Q��s� �
 c3�F<"�TFqR,S8�gK^x�K	R#5ir�r�)r�r6rms& �rr�r�s����I�(�Q�
�m�q�6H�q�q�(�s�!�
!z>=c3�B"�TFqPR4x�K	R#5i)rxN�r.r�s& rr�r�s���F�X��e�e�N�3�3�X�s��active_total�current_unreachable�already_hires_gt500�lowres_total�lowres_with_momentum_src�colorway_safe_upgrades�excluded_no_upgrade_or_dead�excluded_breakdown�
tier2_held�no_hires_sourcezemitted_at_floor>=800�capped_hiresc3�V"�TFqPR4'gK^x�K!	R#5i)r�Nr�r�s& rr�r�!s���M�x�!�5�5�9K�3L�A�A�x�s�)�
)�	by_vendor�width_histogram�coverage_per_floor�ticketzTK-12097�batch�C�parentzTK-12090 / TK-11494�generated_at�Z�generated_byzvp-dw-commerce�storezdesigner-laboratory-sandbox�enginez[reuse ~/Projects/dw-kravet-hires/scripts/apply-hires.mjs (--max-width 500 --only-swappable)�	join_usedapdw_sku exact join EMPTY (Shopify=real X-codes, momentum staging=fabricated DWHD-*). Used manufacturer-code join: shopify mfr_sku tail (code after last '_') = momentum_colorways.alt_sku OR pattern_sku, requiring a UNIQUE resulting image (vendor code encodes pattern+colorway => unique match is colorway-level authoritative). Ambiguous (>1 distinct image) held to tier2.�hires_transformamomentum_colorways.image_url Cloudinary downscale c_scale,w_640 rewritten to c_scale,w_2000 (querystring stripped); fallback = transform removed (original); oversized capped to c_scale,w_5000; all MEASURED. Genuine-upgrade gate: measured hires_le > current AND >= zpx.�no_leakz�apply-hires passes proposed_hires_url as Shopify productCreateMedia originalSource; Shopify downloads + re-hosts on its own CDN, so the momentum cloudinary domain never appears on the storefront.�countsrl�w)�indent�measured_at_utc�
max_lowres�hires_floorzhires long-edge: min=z max=z pxz%
--- sample measured before/after ---:N�Nz  z: cur=zpx -> hires=zpx (z) )r�iXr�i�r�) rprN�print�sys�stderr�cf�ThreadPoolExecutor�	enumerate�maprurr.r�rk�boolr��dictr�datetime�utcnow�	isoformatr
�json�dumprO�OUT_MAP�OUT_MEAS�	OUT_TIER2�	OUT_NOSRC�dumps�minrV)�cands�N�ex�i�_r6�cur_unreachable�lowres�
already_hi�
to_measure�M�	swappable�excluded�
tier2_rows�no_srcr��hist�floors�
excl_breakr��doc�lesrmr�s                      @@r�mainr	�s������E��E�
�A�	�G�A�3�2�
3�#�*�*�E�
�	�	�2�	.�	.�"��b�f�f�_�e�<�a�@�D�A��3�w�!�|��*�1�#�Q�q�c�2����D�A�
/�#(�?�%�Q�X�;�q�q�%�O�?��
X��A�H�+�a�a��k�Z�>W�a�a��F�
X�"�[�U���k�!�!�H�+�PZ�BZ�!�!�U�J�[�	� ���D��V��
�\�#�j�/�IZ�Zk�lo�p�mA�lB�C�JM�JT�JT�U�$�a�V��u�u�^�'<�!��;��S`�A`�!�!�V�J�a��J��A�	�F�q�c�
J�QT�Q[�Q[�\�	�	�	�2�	.�	.�"��b�f�f�]�J�?��C�D�A��3�w�!�|��*�1�#�Q�q�c�2����D�D�
/�
'�6�J�q�%�%��+���J�I�6�%�9�:�a�U�U�4�[���:�H�9��J�
���[�>�[�(����|�Q�|�_�h�Ha�(�!�I�,��!�H�+�{�\]�^f�\g�-�q��/?��QR�Sa�Qb�'�)R�T�
U�� �
Y��A�u�u�^�'<�'<��+��RX�@X�a�a��F�
Y��H�
������!�L�/��/��q��|��a��k���8����=�!1��A�m�,� �!�K�.���*�
��;���Q�U�U�8�_� 5��Q�U�U�?�1�5�5��?�?�G�X`�a�*�D�
�	��$D�	�4��S�>�:�t�C����T�$��%�{�D��t�4D���B��B�B��D�
�F�
(���I�(�I�I���A�3�x��)��g�F�X�F�F�G�J�	���s�?�3��s�:����F��"�A� �#�i�.�%�s�8�}��j��c�*�o��3�v�;���X����M�x�M�M��/��X��?��4��f��F�&	�*�g�s��'���)�)�0�0�2�<�<�>��D��(��.��+��o��E�
	�B�CN��c�S�	�1�	�&���+�C�.	�I�I�c�4���%�a�0��I�I�x��W�c� �(�"3�"3�":�":�"<�"F�"F�"H�3�"N��Z���V�U�T��8�S�!�!�-�	�I�I�v�z�"�D��C�$8��C��I�I�f�d�9�c�*�1�5�	�$�*�*�V�A�
&�'��&/�0�i���}�}�i��0�
�%�c�#�h�Z�u�S��X�J�c�B����T�	�
2����D�
�r�]�]��
��1�Y�<�.��q��{�m�<��*�
��d�ST�SX�SX�Yh�Si�Rj�jl�mn�oz�m{�l|�}�EH�EO�EO�	P��o
/�	.�	.��@��
X��[��b�
/�	.�	.��
7��9��Z��j1s��1\0�%\0�=]�]�]	�+]	�?]	�]�]�0]�]�]�/]�?1]�5%]�&],�],�]1�,]1�&]6�	]6�'];�0]	�])	�__main__i@)4�__doc__r�rPr�r�osr��concurrent.futures�futuresr��collectionsr�urllib.requestrr�urllib.errorrr�PILr�path�dirname�abspath�__file__�HERE�PROJ�join�Drir�r�r�r�r2�environr.rr
r�r�r,rrr!r&r=r_rprur�r	�__name__r�rr�<module>rs_���4A�@�@�@��+�,��	�w�w���r�w�w���x�0�1��	�w�w���t����G�G�L�L��~�&���g�g�l�l�1�-�.��
�'�'�,�,�q�1�
2��
�7�7�<�<��1�2���G�G�L�L��C�D�	��G�G�L�L��9�:�	�
�������e�4�
5�
��"�*�*�.�.���6�7��
��
�
�1���	����$�@
� 
�*
�Z~P�B�z���F�r