ഡേറ്റാഷീറ്റ് ജനറേഷൻ: ഡിമാൻഡ് അനുസരിച്ചും ബാച്ച് രീതിയിലും PDF സൃഷ്ടിക്കൽ
ഈ ലേഖനം ഉൽപ്പന്ന ഡേറ്റാഷീറ്റുകൾ PDF ആയി എങ്ങനെ സൃഷ്ടിക്കുന്നു എന്ന് വിശദീകരിക്കുന്നു, ഇത് ഡിമാൻഡ് അനുസരിച്ച് (ഉപയോക്താക്കൾ അഭ്യർത്ഥിക്കുമ്പോൾ) ബാച്ച് രീതിയിലും (ജനപ്രിയ ഉൽപ്പന്നങ്ങൾക്ക് മുൻകൂട്ടി സൃഷ്ടിക്കൽ) നടത്തുന്നു.
പ്രശ്നം: ഉൽപ്പന്ന ഡേറ്റാഷീറ്റുകൾ സൃഷ്ടിക്കൽ
ഓരോ ഉൽപ്പന്നത്തിനും ഒരു പ്രൊഫഷണൽ PDF ഡേറ്റാഷീറ്റ് ആവശ്യമാണ്, അതിൽ ഇവ അടങ്ങിയിരിക്കും:
-
ഉൽപ്പന്നത്തിന്റെ പേരും ചിത്രങ്ങളും
-
വിഭാഗം അനുസരിച്ച് ഗ്രൂപ്പുചെയ്ത സാങ്കേതിക വിശദാംശങ്ങൾ
-
കമ്പനി ബ്രാൻഡിംഗും കോൺടാക്റ്റ് വിവരങ്ങളും
-
ഒപ്റ്റിമൈസ് ചെയ്ത ലേഔട്ട് (ഒറ്റ പേജ്, സന്തുലിതമായ കോളങ്ങൾ)
എല്ലാ അഭ്യർത്ഥനയിലും PDF സൃഷ്ടിക്കുന്നത് വേഗത കുറഞ്ഞതാണ് (~2 സെക്കൻഡ് ഓരോ PDF-ക്കും). 65,000 SKU-കളും മുൻകൂട്ടി സൃഷ്ടിക്കുന്നത് സ്റ്റോറേജും സമയവും പാഴാക്കുന്നു.
പരിഹാരം: ഹൈബ്രിഡ് സമീപനം
ഞങ്ങൾ രണ്ട് ജനറേഷൻ രീതികൾ ഉപയോഗിക്കുന്നു:
ഡിമാൻഡ് അനുസരിച്ച്: ഉപയോക്താവ് അഭ്യർത്ഥിക്കുമ്പോൾ PDF സൃഷ്ടിക്കുക (ആദ്യമായി)
ബാച്ച്: ജനപ്രിയ ഉൽപ്പന്നങ്ങൾക്കായി PDF-കൾ മുൻകൂട്ടി സൃഷ്ടിക്കുക (ദിവസേന രാത്രി)
ഡിമാൻഡ് അനുസരിച്ചുള്ള ജനറേഷൻ
URL ഘടന
/ds/<sku>.pdf
/ds/<sku>
രണ്ട് URL-കളും ഒരേ PDF സൃഷ്ടിക്കുന്നു.
അഭ്യർത്ഥന ഫ്ലോ
@web.route("/ds/<sku>.pdf")
def datasheet(sku: str):
# Validate SKU
# ... (implementation details omitted)
ജനറേഷൻ പ്രക്രിയ
ഘട്ടം 1: ഉൽപ്പന്ന ഡേറ്റ ലഭിക്കുക
# Product name
name = expand_sku(sku)
# ... (implementation details omitted)
ഘട്ടം 2: കോളങ്ങൾ സന്തുലിതമാക്കുക
വിശേഷതകൾ 3 കോളങ്ങളിലായി വിതരണം ചെയ്യുന്നു, ലൈൻ എണ്ണം സന്തുലിതമാക്കാൻ:
# Calculate lines per feature group
all_groups = []
for heading, f_items in features.items():
# ... (implementation details omitted)
ഘട്ടം 3: ചിത്രങ്ങളുടെ ഉയരം കണക്കാക്കുക
# Main image height (proportional to aspect ratio)
with Image.open(main_image_path) as img:
main_width, main_height = img.size
# ... (implementation details omitted)
ഘട്ടം 4: സ്പേസർ കണക്കാക്കുക
ഫുട്ടർ പേജിന്റെ അടിയിലേക്ക് തള്ളുക:
available_height = 25.0 # cm
content_height = total_image_height + text_height_cm
spacer_height = max(0, available_height - content_height)
ഘട്ടം 5: HTML റെൻഡർ ചെയ്യുക
html = render_template(
"datasheet.html",
sku=sku,
# ... (implementation details omitted)
ഘട്ടം 6: PDF സൃഷ്ടിക്കുക
options = {
"page-size": "A4",
"enable-local-file-access": None,
"load-error-handling": "ignore",
"load-media-error-handling": "ignore",
"no-stop-slow-scripts": None
}
pdf_data = pdfkit.from_string(html, options=options)
ഘട്ടം 7: ആദ്യ പേജ് മാത്രം സൂക്ഷിക്കുക
reader = PdfReader(BytesIO(pdf_data))
if len(reader.pages) > 1:
writer = PdfWriter()
writer.add_page(reader.pages[0])
output = BytesIO()
writer.write(output)
pdf_data = output.getvalue()
പ്രകടനം
ജനറേഷൻ സമയം: ~2 സെക്കൻഡ് ഓരോ PDF-ക്കും
കാഷിംഗ്: കാഷിംഗ് ഇല്ല (എല്ലായ്പ്പോഴും പുതിയത്)
ഗുണം: ഏറ്റവും പുതിയ ഉൽപ്പന്ന ഡേറ്റയുമായി എല്ലായ്പ്പോഴും അപ്ഡേറ്റ് ആയിരിക്കും
ബാച്ച് ജനറേഷൻ
ഉദ്ദേശ്യം
ജനപ്രിയ ഉൽപ്പന്നങ്ങൾക്കായി PDF-കൾ മുൻകൂട്ടി സൃഷ്ടിക്കുക, ഡിമാൻഡ് അനുസരിച്ചുള്ള ലോഡ് കുറയ്ക്കാൻ.
സ്ക്രിപ്റ്റ് സ്ഥാനം
scripts/utils/generate_datasheets.py
മാറ്റങ്ങൾ ട്രാക്ക് ചെയ്യൽ
ഓരോ SKU-യുമായി ബന്ധപ്പെട്ട productdb.json വിഭാഗങ്ങളിലെ മാറ്റങ്ങൾ ഞങ്ങൾ ട്രാക്ക് ചെയ്യുന്നു:
def get_sku_productdb_hash(sku: str) -> str:
"""Get hash of productdb sections relevant to this SKU."""
with open(PRODUCTDB_PATH, "r") as f:
# ... (implementation details omitted)
മുൻഗണന
അഭ്യർത്ഥന ആവൃത്തി അനുസരിച്ച് ഞങ്ങൾ SKU-കൾക്ക് മുൻഗണന നൽകുന്നു:
def load_popular_skus() -> List[str]:
"""Load popular SKUs from access logs."""
try:
# ... (implementation details omitted)
ജനറേഷൻ തന്ത്രം
def batch_generate():
# Load hash cache
hash_cache = load_hash_cache()
# ... (implementation details omitted)
ഷെഡ്യൂളിംഗ്
ബാച്ച് ജനറേഷൻ ദിവസേന രാത്രി cron വഴി പ്രവർത്തിക്കുന്നു:
0 2 * * * cd /home/ubuntu/manage && python scripts/utils/generate_datasheets.py
സ്റ്റോറേജ്
ലോക്കൽ: /home/ubuntu/web-static/ds/<sku>.pdf
S3: s3://thinvent-web-static/ds/<sku>.pdf
CDN: CloudFront വഴി സേവനം നൽകുന്നു
ടെംപ്ലേറ്റ് ഘടന
ഡേറ്റാഷീറ്റ് ടെംപ്ലേറ്റ് 3-കോളം ലേഔട്ട് ഉപയോഗിക്കുന്നു:
<div class="container">
<!-- Header with logo and product name -->
<div class="header">
<img src="logo.png">
<h1>{{ name }}</h1>
</div>
<!-- Main image -->
<img src="{{ images[0][1] }}" style="width: 9.5cm">
<!-- Thumbnails (up to 4) -->
<div class="thumbnails">
{% for name, url in images[1:5] %}
<img src="{{ url }}" style="width: 4.5cm">
{% endfor %}
</div>
<!-- Features in 3 columns -->
<div class="features">
<div class="column">
{% for heading, items in features1 %}
<h3>{{ heading }}</h3>
{% for name, value in items.items() %}
<div><strong>{{ name }}:</strong> {{ value }}</div>
{% endfor %}
{% endfor %}
</div>
<div class="column">
<!-- features2 -->
</div>
<div class="column">
<!-- features3 -->
</div>
</div>
<!-- Spacer to push footer down -->
<div style="height: {{ spacer_height }}cm"></div>
<!-- Footer with contact info -->
<div class="footer">
<p>www.thinvent.in | sales@thinvent.in | +91-124-4343177</p>
</div>
</div>
കോൺഫിഗറേഷൻ
ലേഔട്ട് നിയന്ത്രിക്കുന്ന സ്ഥിരാങ്കങ്ങൾ:
DATASHEET_COLUMN_COUNT = 3
DATASHEET_HEADING_LINE_WEIGHT = 2 # Lines per heading
DATASHEET_FEATURE_NAME_MAX_LEN = 30 # Chars before wrapping
DATASHEET_FEATURE_VALUE_CHARS_PER_LINE = 40 # Chars per line
PDF_PAGE_SIZE = "A4"
ഇന്റഗ്രേഷൻ പോയിന്റുകൾ
ഉൽപ്പന്ന പേജുകൾ
ഡേറ്റാഷീറ്റിലേക്കുള്ള ലിങ്ക്:
<a href="/ds/{{ sku }}.pdf" target="_blank">Download Datasheet</a>
Google Shopping
ഉൽപ്പന്ന ഫീഡിൽ ഡേറ്റാഷീറ്റുകൾ ലിങ്ക് ചെയ്തിരിക്കുന്നു:
<g:product_detail>
<g:section_name>Datasheet</g:section_name>
<g:attribute_name>PDF</g:attribute_name>
<g:attribute_value>https://www.thinvent.in/ds/{{ sku }}.pdf</g:attribute_value>
</g:product_detail>
ഇമെയിൽ കാമ്പെയ്നുകൾ
ഉദ്ധരണി ഇമെയിലുകളിൽ ഡേറ്റാഷീറ്റുകൾ അറ്റാച്ച് ചെയ്തിരിക്കുന്നു.
പിശക് കൈകാര്യം ചെയ്യൽ
അസാധുവായ SKU
if not check_sku(sku):
abort(422, description="Product not found.")
ജനറേഷൻ പരാജയം
try:
pdf_data = generate_datasheet_pdf(sku)
if pdf_data is None:
abort(500, description="PDF generation failed.")
except Exception as e:
logger.error(f"PDF generation failed for {sku}: {e}")
abort(500, description="PDF generation failed.")
ചിത്രങ്ങൾ കാണാതായത്
try:
with Image.open(image_path) as img:
width, height = img.size
except Exception:
# Use default dimensions
width, height = 800, 600
അവലംബങ്ങൾ
ലൈബ്രറികൾ
ബന്ധപ്പെട്ട ലേഖനങ്ങൾ
-
Feature Extraction - ഉൽപ്പന്ന സവിശേഷതകൾ ലഭിക്കൽ
-
Content AI Generation - ഉൽപ്പന്ന വിവരണങ്ങൾ
-
SKU Structure - ഉൽപ്പന്ന ഐഡന്റിഫയറുകൾ
സംഗ്രഹം
ഡേറ്റാഷീറ്റ് ജനറേഷൻ ഒരു ഹൈബ്രിഡ് സമീപനം ഉപയോഗിക്കുന്നു:
ഡിമാൻഡ് അനുസരിച്ച്:
-
✅ ഉപയോക്താവ് അഭ്യർത്ഥിക്കുമ്പോൾ സൃഷ്ടിക്കുക
-
✅ എല്ലായ്പ്പോഴും അപ്ഡേറ്റ് ആയിരിക്കും
-
✅ സ്റ്റോറേജ് പാഴാക്കുന്നില്ല
-
✅ ~2 സെക്കൻഡ് ഓരോ PDF-ക്കും
ബാച്ച്:
-
✅ ജനപ്രിയ ഉൽപ്പന്നങ്ങൾ മുൻകൂട്ടി സൃഷ്ടിക്കുക
-
✅ productdb മാറ്റങ്ങൾ ട്രാക്ക് ചെയ്യുക
-
✅ അഭ്യർത്ഥന ആവൃത്തി അനുസരിച്ച് മുൻഗണന നൽകുക
-
✅ ദിവസേന രാത്രി cron ജോലി
പ്രക്രിയ:
-
✅ ഉൽപ്പന്ന ഡേറ്റ ലഭിക്കുക (പേര്, ചിത്രങ്ങൾ, വിശേഷതകൾ, വിവരണം)
-
✅ വിശേഷതകൾ 3 കോളങ്ങളിലായി സന്തുലിതമാക്കുക
-
✅ ചിത്രങ്ങളുടെ ഉയരം കണക്കാക്കുക
-
✅ HTML ടെംപ്ലേറ്റ് റെൻഡർ ചെയ്യുക
-
✅ pdfkit ഉപയോഗിച്ച് PDF സൃഷ്ടിക്കുക
-
✅ ആദ്യ പേജ് മാത