การตรวจสอบคำตอบ
วิธีหนึ่งในการรับประกันคุณภาพข้อมูลคือการเพิ่ม constraint ให้กับฟิลด์ข้อมูลในแบบฟอร์มของคุณ Constraint ช่วยป้องกันผู้ใช้จากการป้อนคำตอบที่ไม่ถูกต้องหรือเป็นไปไม่ได้ ตัวอย่างเช่น เมื่อถามรายได้ของบุคคล คุณต้องการหลีกเลี่ยงค่าที่ไม่สมเหตุสมผล
- เพิ่มคอลัมน์ใหม่ชื่อ “constraint” ในแบบฟอร์มของคุณ
- ในคอลัมน์ “constraint” ป้อนสูตรที่ระบุขีดจำกัดของคำตอบ
ตัวอย่าง
ลองพิจารณาตัวอย่างที่เราต้องการเพิ่ม constraint สำหรับรายได้ของบุคคล constraint กำหนดให้รายได้อยู่ระหว่าง $0 ถึง $1,000,000:
name | constraint |
|---|---|
| Income | . >= 0 & . <= 1000000 |
Hard constraint
Hard constraint จะบล็อกการส่งแบบฟอร์มทั้งหมดหากค่าที่ป้อนไม่ตรงตามนิพจน์ ผู้เก็บข้อมูลไม่สามารถดำเนินการต่อได้จนกว่าจะป้อนค่าที่ถูกต้อง
type | name | label | constraint | constraint_message |
|---|---|---|---|---|
| integer | age | Age of respondent | . > 0 and . <= 120 | Age must be between 1 and 120 |
| decimal | temperature | Body temperature (°C) | . >= 35 and . <= 42 | Temperature must be between 35°C and 42°C |
| text | phone | Phone number | regex(., '^[0-9]{10}$') | Enter a 10-digit phone number |
การใช้ regex() เพื่อตรวจสอบรูปแบบ
ฟังก์ชัน regex(value, pattern) ทดสอบค่ากับนิพจน์ปกติ:
type | name | label | constraint | constraint_message |
|---|---|---|---|---|
| text | Email address | regex(., '^[^@]+@[^@]+\.[^@]+$') | Enter a valid email address | |
| text | zip_code | ZIP code | regex(., '^[0-9]{5}$') | Enter a 5-digit ZIP code |
Soft alert
Soft alert (หรือเรียกว่า soft constraint หรือคำเตือน) เตือนผู้เก็บข้อมูลว่าค่าดูผิดปกติ แต่ยังคงอนุญาตให้ดำเนินการต่อได้ ซึ่งมีประโยชน์เมื่อค่าถูกต้องตามเทคนิคแต่ไม่น่าจะเป็นทางสถิติ
รูปแบบทั่วไปคือใช้ note กับนิพจน์ relevant ที่แสดงค่าที่น่าสงสัย จับคู่กับคำถาม acknowledge เพื่อยืนยัน:
type | name | label | relevant |
|---|---|---|---|
| integer | children | Number of children | |
| note | children_warning | Warning: You entered ${children} children. Please confirm this is correct. | . > 15 |
| trigger | children_confirm | Confirm the number of children is correct | ${children} > 15 |
ความแตกต่างระหว่าง hard constraint และ soft constraint มีความสำคัญต่อคุณภาพข้อมูล ใช้ hard constraint สำหรับค่าที่เป็นไปไม่ได้ตามตรรกะ ใช้ soft alert สำหรับค่าที่ไม่น่าเกิดขึ้นทางสถิติแต่ไม่ใช่สิ่งที่เป็นไปไม่ได้