ഡാറ്റാഷീറ്റ് ജനറേഷൻ: ഓൺ-ഡിമാൻഡ്, ബാച്ച് PDF നിർമ്മാണം
ഈ ലേഖനം ഉൽപ്പന്ന ഡാറ്റാഷീറ്റുകൾ PDF ആയി എങ്ങനെ നിർമ്മിക്കുന്നുവെന്ന് വിശദീകരിക്കുന്നു — ഓൺ-ഡിമാൻഡ് ആയും (ഉപയോക്താക്കൾ അഭ്യർത്ഥിക്കുമ്പോൾ) ബാച്ച് ആയും (ജനപ്രിയ ഉൽപ്പന്നങ്ങൾക്കായി മുൻകൂട്ടി നിർമ്മിക്കുന്നത്).
പ്രശ്നം: ഉൽപ്പന്ന ഡാറ്റാഷീറ്റുകൾ നിർമ്മിക്കൽ
ഓരോ ഉൽപ്പന്നത്തിനും ഒരു പ്രൊഫഷണൽ PDF ഡാറ്റാഷീറ്റ് ആവശ്യമാണ്, അതിൽ ഇവ ഉണ്ടായിരിക്കണം:
-
ഉൽപ്പന്നത്തിന്റെ പേരും ചിത്രങ്ങളും
-
വിഭാഗം അനുസരിച്ച് ഗ്രൂപ്പ് ചെയ്ത സാങ്കേതിക സവിശേഷതകൾ
-
കമ്പനി ബ്രാൻഡിംഗും കോൺടാക്റ്റ് വിവരങ്ങളും
-
മെച്ചപ്പെടുത്തിയ ലേഔട്ട് (ഒറ്റ പേജ്, സന്തുലിതമായ കോളങ്ങൾ)
ഓരോ അഭ്യർത്ഥനയിലും PDF നിർമ്മിക്കുന്നത് മന്ദഗതിയാണ് (ഓരോ PDF-നും ~2 സെക്കൻഡ്). എല്ലാ 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()
പ്രകടനം
ജനറേഷൻ സമയം: ഓരോ PDF-നും ~2 സെക്കൻഡ്
കാഷിംഗ്: കാഷിംഗ് ഇല്ല (എപ്പോഴും പുതിയത്)
നേട്ടം: ഏറ്റവും പുതിയ ഉൽപ്പന്ന ഡാറ്റയുമായി എപ്പോഴും അപ്ഡേറ്റ് ചെയ്തിരിക്കുന്നു
ബാച്ച് ജനറേഷൻ
ഉദ്ദേശ്യം
ഓൺ-ഡിമാൻഡ് ലോഡ് കുറയ്ക്കാൻ ജനപ്രിയ ഉൽപ്പന്നങ്ങൾക്കായി 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="/s/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
റഫറൻസുകൾ
ലൈബ്രറികൾ
ബന്ധപ്പെട്ട ലേഖനങ്ങൾ
-
ഫീച്ചർ എക്സ്ട്രാക്ഷൻ - ഉൽപ്പന്ന സവിശേഷതകൾ എടുക്കൽ
-
Content AI Generation - ഉൽപ്പന്ന വിവരണങ്ങൾ
-
SKU ഘടന - ഉൽപ്പന്ന ഐഡന്റിഫയറുകൾ
സംഗ്രഹം
ഡാറ്റാഷീറ്റ് ജനറേഷൻ ഒരു ഹൈബ്രിഡ് സമീപനം ഉപയോഗിക്കുന്നു:
ഓൺ-ഡിമാൻഡ്:
-
ഉപയോക്താവ് അഭ്യർത്ഥിക്കുമ്പോൾ നിർമ്മിക്കുന്നു
-
എപ്പോഴും അപ്ഡേറ്റ് ചെയ്തിരിക്കുന്നു
-
സ്റ്റോറേജ് പാഴാക്കുന്നില്ല
-
ഓരോ PDF-നും ~2 സെക്കൻഡ്
ബാച്ച്:
-
ജനപ്രിയ ഉൽപ്പന്നങ്ങൾ മുൻകൂട്ടി നിർമ്മിക്കുന്നു
-
productdb മാറ്റങ്ങൾ ട്രാക്ക് ചെയ്യുന്നു
-
അഭ്യർത്ഥന ആവൃത്തി അനുസരിച്ച് മുൻഗണന
-
രാത്രി cron ജോലി
പ്രക്രിയ:
-
ഉൽപ്പന്ന ഡാറ്റ എടുക്കുക (പേര്, ചിത്രങ്ങൾ, ഫീച്ചറുകൾ, വിവരണം)
-
3 കോളങ്ങളിൽ ഫീച്ചറുകൾ സന്തുലിതമാക്കുക
-
ഇമേജ് ഉയരങ്ങൾ കണക്കാക്കുക
-
HTML ടെംപ്ലേറ്റ് റെൻഡർ ചെയ്യുക
-
pdfkit ഉപയോഗിച്ച് PDF നിർമ്മിക്കുക
-
ആദ്യ പേജ് മാത്രം സൂക്ഷിക്കുക
സ്റ്റോറേജ്:
-
ലോക്കൽ:
/home/ubuntu/web-static/ds/ -
S3:
s3://thinvent-web-static/ds/ -
CDN: CloudFront distribution
ഈ ഹൈബ്രിഡ് സമീപനം പുതുമ (ഓൺ-ഡിമാൻഡ്) പ്രകടനവുമായി (ബാച്ച് പ്രീ-ജനറേഷൻ) സന്തുലിതമാക്കുന്നു.