Blockchain-based food safety traceability information management system
Patent Information
- Application Number
- CN202610886901.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-18
- Publication Date
- 2026-09-04
AI Technical Summary
[0003]针对现有基于区块链的食品安全溯源方法中,冷链运输环节的温度传感器因瞬态故障产生异常读数后,系统无法在上链前有效识别此类由设备可靠性问题导致的孤立异常点,导致错误数据被不可篡改地写入区块链并引发合格食品被误判为不合格而召回或销毁,同时现有滤波方法难以区分传感器偶发故障与真实温度突变且会改变原始数据的问题,提供一种既能识别并修复传感器瞬态故障产生的异常数据以避免错误数据上链、又能保留完整故障与修复记录以供审计的溯源信息管理方法
[0052] (1) By projecting the data segment to be tested onto an overcomplete time-series base library and calculating the reconstruction deviation, combined with the judgment mechanism for continuous isolated anomalies, it is possible to effectively distinguish between occasional abnormal readings caused by sensor transient failures (such as voltage instability) and actual temperature exceedance events in cold chain transportation. Only when an isolated anomaly is determined to be continuous and does not exceed 3 sampling points is the corresponding site marked and replaced by reconstruction using normal sites, avoiding the writing of such erroneous data caused by equipment reliability issues into the blockchain, thereby reducing the economic losses of qualified food being wrongly recalled or destroyed due to false over-temperature reports.
Smart Images

Figure CN122694476A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of food safety traceability technology, and more specifically to a blockchain-based food safety traceability information management system. Background Technology
[0002] Currently, blockchain-based food safety traceability information management methods have been applied in the cold chain logistics field. Existing technologies typically use IoT sensors to automatically collect ambient temperature data during transportation, storing the raw data in an off-chain database while simultaneously writing the corresponding data hashes to the blockchain. The immutability of the blockchain ensures the authenticity of the stored data. For example, temperature sensors are deployed inside refrigerated trucks to collect temperature values at a fixed frequency. The system generates a hash for each sampling time along with a timestamp and equipment identifier, and uploads it to the blockchain, forming a complete cold chain temperature traceability chain.
[0003] In existing blockchain-based food safety traceability methods, when temperature sensors in the cold chain transportation process generate abnormal readings due to transient malfunctions, the system cannot effectively identify such isolated anomalies caused by equipment reliability issues before uploading them to the blockchain. This results in erroneous data being immutably written to the blockchain, leading to qualified food being mistakenly judged as unqualified and recalled or destroyed. At the same time, existing filtering methods have difficulty distinguishing between occasional sensor malfunctions and actual temperature changes, which alter the original data. This paper proposes a traceability information management method that can both identify and repair abnormal data generated by transient sensor malfunctions to prevent erroneous data from being uploaded to the blockchain, and retain complete fault and repair records for auditing. Summary of the Invention
[0004] The purpose of this invention is to provide a blockchain-based food safety traceability information management system to solve the problems mentioned above.
[0005] The objective of this invention can be achieved through the following technical solutions:
[0006] A blockchain-based food safety traceability information management system includes:
[0007] The data acquisition and window capture module continuously acquires time-series data from temperature sensors during cold chain transportation and captures the current data segment as the data segment to be tested with a fixed window length.
[0008] The sparse reconstruction and deviation calculation module projects the data segment to be tested onto a pre-generated overcomplete time series base library, solves for the minimum sparse coding coefficients, and reconstructs the comparison data segment based on the sparse coding coefficients to obtain the reconstruction deviation between the data segment to be tested and the comparison data segment.
[0009] The anomaly identification and missing point marking module identifies the number of consecutive sampling points that deviate from the baseline in the data segment to be tested when the reconstruction deviation exceeds the preset tolerance threshold. If the number of sampling points is not greater than the preset isolated window value, it determines that there is a sensor transient fault and marks the sampling points as missing points.
[0010] The missing site reconstruction and repair module reconstructs the temperature values of the missing sites based on the unlabeled normal sites in the data segment to be tested, and obtains the repaired complete data segment by using an overcomplete time series base library.
[0011] The hash-based evidence storage and off-chain storage module performs hash operations on the repaired complete data segment to obtain a data fingerprint. After associating the data fingerprint with the timestamp and device identifier, it writes it into the blockchain network. At the same time, it stores the original fault record and repair process metadata off-chain and establishes an index.
[0012] As a further aspect of the present invention: the reconstruction deviation specifically includes:
[0013] The data segment to be tested is expressed as a linear combination of the basis vectors in the overcomplete time series basis library, and the maximum number of basis vectors used in the linear combination is preset.
[0014] By iteratively selecting the basis vector with the largest inner product with the current remaining residual from the overcomplete time series basis library, and updating the linear combination coefficients, the number of selected basis vectors reaches the maximum number.
[0015] The final obtained linear combination coefficients and corresponding basis vectors are used to construct a comparison data segment;
[0016] Calculate the Euclidean norm of the difference between the data segment to be tested and the data segment to be compared, and use the Euclidean norm as the reconstruction deviation.
[0017] As a further aspect of the present invention: the updating of the linear combination coefficients specifically includes:
[0018] Obtain the target basis vector selected from the overcomplete temporal basis library in the current iteration, and read the remaining residual from the previous round;
[0019] Calculate the inner product of the target basis vector and the remaining residual from the previous round, and use the inner product as the current weight increment;
[0020] The current weight increment is added to the original weights corresponding to the target basis vector in the linear combination coefficients to obtain the updated linear combination coefficients;
[0021] The updated residual is obtained by subtracting the current weight increment multiplied by the target basis vector from the residual of the previous round, and then using it for the next iteration.
[0022] As a further aspect of the present invention: marking the sampling points as missing sites specifically includes:
[0023] Calculate the difference between the original temperature value of each sampling point in the data segment to be tested and the reconstructed temperature value at the corresponding position in the comparison data segment to form a deviation difference sequence;
[0024] Using the deviation from the baseline as the upper and lower bounds, sampling points with an absolute value greater than the deviation from the baseline are selected from the deviation difference sequence and regarded as candidate outliers;
[0025] Traverse the candidate outliers in chronological order, count the sampling step length occupied by consecutively occurring candidate outliers, and use the sampling step length as the number of consecutive sampling points that deviate from the baseline.
[0026] The number of sampling points is compared with the preset isolated window value. When the number of sampling points is not greater than the preset isolated window value, the sampling points corresponding to the continuously appearing candidate abnormal points are determined to be caused by the sensor transient fault, and these sampling points are marked as missing sites.
[0027] As a further aspect of the present invention: obtaining the repaired complete data segment specifically includes:
[0028] Extract all normal sites that are not marked as missing sites and their corresponding location indices from the data segment to be tested to form an incomplete observation sequence;
[0029] From the incomplete time series base library, basis vector rows corresponding to the position indices in the incomplete observation sequence are selected to form a dimension-reduced base library;
[0030] Solve for sparse combination coefficients that can linearly represent incomplete observation sequences in a reduced-dimensional basis library, while minimizing the number of basis vectors used;
[0031] The sparse combination coefficients are linearly combined with the basis vector rows corresponding to the missing sites in the overcomplete time series base library to calculate the reconstruction temperature value of each missing site. The reconstruction temperature value is then filled into the corresponding position to obtain the repaired complete data segment.
[0032] As a further aspect of the present invention: the construction of the dimensionality reduction library specifically includes:
[0033] Based on the location index of normal sites in the incomplete observation sequence, a binary selection vector of the same length as the data segment to be tested is constructed, where the element corresponding to the normal site is 1 and the other elements are zero.
[0034] Construct a selection matrix with the binary selection vector as the diagonal element, and multiply the selection matrix by the complete temporal base library to obtain a transition base library with the same number of rows and columns.
[0035] Remove all rows with zero elements from the transition base library and keep the remaining non-zero rows to form the reduced-dimensional base library.
[0036] As a further aspect of the present invention: the step of solving for the sparse combination coefficients that can linearly represent the incomplete observation sequence in the reduced-dimensional library specifically includes:
[0037] Initialize the combination coefficients to a zero vector and use the incomplete observation sequence as the current residual;
[0038] Find the column with the largest absolute value of the inner product with the current residual from the reduced dimensionality library, select the corresponding column as the input column, and record the inner product value of the column as the combination coefficient increment;
[0039] Subtract the combination coefficient increment multiplied by the selected result from the current residual to obtain the updated residual;
[0040] Repeat the column selection and residual update process until the preset maximum number of iterations is reached or the magnitude of the current residual is less than the preset convergence threshold, and use the final accumulated combination coefficients as sparse combination coefficients.
[0041] As a further aspect of the present invention: the establishment of the index specifically includes:
[0042] The original fault records and repair process metadata are concatenated into an audit string in chronological order, and the hash value of the audit string is calculated as the audit fingerprint.
[0043] The audit fingerprint and data fingerprint are combined to generate a linked credential;
[0044] Write the associated credentials into the blockchain network and store them in the same transaction record as the timestamp and device identifier;
[0045] The audit string is stored in the off-chain storage area, and a search directory is established using the audit fingerprint as the unique index key.
[0046] As a further aspect of the present invention: the calculation of the hash value of the audit string as the audit fingerprint specifically includes:
[0047] The sensor identifier, fault start time, original anomaly value sequence and reconstructed value sequence in the original fault record are concatenated in a fixed order and separated by commas to form the first substring.
[0048] The total number of iterations, the magnitude of the final remaining residual, and the position index of the selected basis vector in the metadata of the repair process are concatenated in another fixed order and separated by semicolons to form a second substring.
[0049] The current timestamp, device identifier, first substring, and second substring are concatenated in sequence using vertical bar separators, and invisible control characters are added at the beginning and end to form the audit string;
[0050] Two different hashing methods were applied to the audit string to obtain an intermediate hash result, and then a second hashing operation was performed on the intermediate hash result to obtain the audit fingerprint.
[0051] The beneficial effects of this invention are:
[0052] (1) By projecting the data segment to be tested onto an overcomplete time-series base library and calculating the reconstruction deviation, combined with the judgment mechanism for continuous isolated anomalies, it is possible to effectively distinguish between occasional abnormal readings caused by sensor transient failures (such as voltage instability) and actual temperature exceedance events in cold chain transportation. Only when an isolated anomaly is determined to be continuous and does not exceed 3 sampling points is the corresponding site marked and replaced by reconstruction using normal sites, avoiding the writing of such erroneous data caused by equipment reliability issues into the blockchain, thereby reducing the economic losses of qualified food being wrongly recalled or destroyed due to false over-temperature reports.
[0053] (2) Data fingerprints are obtained by hashing the repaired complete data segments and stored on the blockchain. Simultaneously, the original fault record and repair process metadata are concatenated into an audit string. Audit fingerprints are generated using two different hash algorithms, and then combined with the data fingerprints to form an associated credential, which is written into the same transaction record. Only the associated credential is retained on the blockchain, while the complete audit string is stored off-chain and indexed by the audit fingerprint. When it is necessary to trace a fault handling process, the off-chain data can be quickly read using the audit fingerprint, and the hash can be recalculated for comparison. This maintains the immutability of the blockchain while preserving all traces of the original sensor anomalies and reconstruction operations, providing verifiable audit evidence for subsequent accident analysis and liability determination. Attached Figure Description
[0054] The invention will now be further described with reference to the accompanying drawings.
[0055] Figure 1 This is a system block diagram of the present invention. Detailed Implementation
[0056] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] Please see Figure 1 As shown, this invention is a blockchain-based food safety traceability information management system, comprising:
[0058] The data acquisition and window capture module continuously acquires time-series data from temperature sensors during cold chain transportation and captures the current data segment as the data segment to be tested with a fixed window length.
[0059] The sparse reconstruction and deviation calculation module projects the data segment to be tested onto a pre-generated overcomplete time series base library, solves for the minimum sparse coding coefficients, and reconstructs the comparison data segment based on the sparse coding coefficients to obtain the reconstruction deviation between the data segment to be tested and the comparison data segment.
[0060] The anomaly identification and missing point marking module identifies the number of consecutive sampling points that deviate from the baseline in the data segment to be tested when the reconstruction deviation exceeds the preset tolerance threshold. If the number of sampling points is not greater than the preset isolated window value, it determines that there is a sensor transient fault and marks the sampling points as missing points.
[0061] The missing site reconstruction and repair module reconstructs the temperature values of the missing sites based on the unlabeled normal sites in the data segment to be tested, and obtains the repaired complete data segment by using an overcomplete time series base library.
[0062] The hash-based evidence storage and off-chain storage module performs hash operations on the repaired complete data segment to obtain a data fingerprint. After associating the data fingerprint with the timestamp and device identifier, it writes it into the blockchain network. At the same time, it stores the original fault record and repair process metadata off-chain and establishes an index.
[0063] In the data acquisition and window truncation module, time-series data from temperature sensors are continuously acquired during cold chain transportation, and the current data segment is truncated into a fixed window length as the data segment to be examined. Specifically, this includes:
[0064] During cold chain transportation, multiple temperature sensors are deployed, such as inside refrigerated truck compartments or near cold storage shelves. Each sensor is connected to an onboard data acquisition terminal via a single bus. The data acquisition terminal has a built-in real-time clock and flash memory, continuously reading the temperature values output by the sensors at a sampling frequency of once every 10 seconds, and adding timestamps and sensor identifiers to form raw temperature time-series data. The raw data cached by the acquisition terminal is first processed by median filtering to eliminate obvious electrical noise, and then the current data segment is sequentially extracted in a fixed window of 30 sampling points (corresponding to a 5-minute duration) as the data segment to be verified. If the last segment has less than 30 sampling points, the segment is discarded or the next complete window is waited for. Each data segment to be verified maintains the original sampling order and is temporarily stored in the acquisition terminal's running memory in the form of a floating-point array for subsequent processing steps. At the same time, the acquisition terminal periodically calibrates its local clock via a network time protocol to ensure that the timestamp error of each sampling point is less than 1 second. The sensor installation locations are avoided in areas with direct cold air vents and door gaps to reduce the impact of local airflow disturbances on the measurement. Throughout the transportation process, the data acquisition terminal continuously performs interception operations, maintaining a 50% overlap between adjacent data segments to be tested (i.e., a sliding step size of 15 sampling points) to ensure the continuity of temperature changes. After interception, the data segment to be tested, along with its start timestamp, end timestamp, and corresponding sensor number, is passed to the next step for processing.
[0065] In the sparse reconstruction and deviation calculation module, the data segment to be examined is projected onto a pre-generated overcomplete time series base library, the minimum sparse coding coefficients are solved, and the comparison data segment is reconstructed based on the sparse coding coefficients to obtain the reconstruction deviation between the data segment to be examined and the comparison data segment. Specifically, this includes:
[0066] An overcomplete time-series base library is pre-generated. Before the cold chain equipment is put into normal use, temperature data is collected from the equipment under healthy operating conditions for at least 72 hours, with a sampling period of 10 seconds, to obtain the raw temperature sequence. This sequence is divided into multiple overlapping training sample segments with a fixed window length of 30 sampling points, and the overlap rate of adjacent sample segments is 50%. K-singular value decomposition is used to learn the dictionary for all the above training sample segments, with 60 dictionary atoms, each atom having a length of 30 sampling points, and 50 iterations, ultimately resulting in an overcomplete time-series base library containing 60 basis vectors, each a 30-dimensional numerical sequence. This overcomplete time-series base library is stored in the local memory of the data acquisition terminal for subsequent processing.
[0067] For the currently obtained data segment to be tested, it is expressed as a linear combination of the basis vectors in the overcomplete time series base library. The maximum number of basis vectors used in the linear combination is preset to 5. The specific process of solving the minimum sparse coding coefficients is as follows: Initialize the linear combination coefficients as an all-zero vector, the length of which is equal to the number of basis vectors in the overcomplete time series base library (i.e., 60), and use the data segment to be tested as the initial residual. Then, begin iteration. In each iteration, select the basis vector with the largest absolute value of its inner product with the current residual from the overcomplete time series base library, and record the index of this basis vector. In each iteration, the linear combination coefficients are updated as follows: calculate the inner product of the selected basis vector and the current residual, and use this inner product value as the current weight increment; then, add this weight increment to the original weights corresponding to this basis vector in the linear combination coefficients to obtain the updated linear combination coefficients; finally, subtract the weight increment multiplied by the selected basis vector from the current residual to obtain the updated residual, which is used for the next iteration. Repeat the above iterative process until the number of selected basis vectors reaches the preset maximum number of 5.
[0068] Using the final obtained linear combination coefficients and the corresponding 5 basis vectors, a new data segment, called the comparison data segment, is constructed using linear combinations. The specific construction method is as follows: each selected basis vector is multiplied by its corresponding linear combination coefficient, and then all products are summed element-wise to obtain the comparison data segment. This comparison data segment has the same length as the test data segment (30 sampling points). The reconstruction deviation between the test data segment and the comparison data segment is measured using the Euclidean norm. The specific method for calculating the reconstruction deviation is as follows: the sampled values at corresponding positions in the test data segment and the comparison data segment are subtracted to obtain 30 differences; the square of each difference is calculated, and then all squared values are summed to obtain the total; finally, the square root of the sum is the reconstruction deviation.
[0069] In the iterative update of the linear combination coefficients described above, the specific operations for each iteration are as follows: First, obtain the target basis vector selected from the overcomplete temporal base library in the current iteration, and read the remaining residual obtained at the end of the previous iteration; calculate the inner product of the target basis vector and the remaining residual of the previous iteration (i.e., the sum of the product of corresponding position values), and use this inner product as the current weight increment; then, find the position corresponding to the target basis vector in the current linear combination coefficient vector, add its original weight to the current weight increment, and obtain the updated linear combination coefficients; finally, subtract the result of the current weight increment multiplied by the target basis vector from the remaining residual of the previous iteration (i.e., after multiplying each dimension of the basis vector by the weight increment, subtract it from the corresponding dimension of the remaining residual), and obtain the updated remaining residual, which will be used for the next iteration. If the same basis vector is selected again in subsequent iterations, its weights will continue to be accumulated in the same way. After all iterations are completed, the final linear combination coefficients are the minimum sparse coding coefficients.
[0070] In the anomaly detection and missing data marking module, when the reconstruction deviation exceeds a preset tolerance threshold, the number of consecutive sampling points in the data segment to be tested that deviate from the baseline is identified. If the number of sampling points is not greater than a preset isolated window value, a sensor transient fault is determined to exist, and the sampling points are marked as missing sites. Specifically, this includes:
[0071] Set a preset tolerance threshold. With the cold chain equipment operating healthily, collect no fewer than 100 data segments to be inspected. Calculate the reconstruction deviation between each data segment and its comparison data segment, obtaining a set of reconstruction deviation values. Calculate the average and standard deviation of this set of values, and set the preset tolerance threshold to the average plus three times the standard deviation. This threshold is stored in the local configuration of the data acquisition terminal and used to determine whether the current data segment to be inspected needs anomaly identification.
[0072] Set the baseline deviation and preset isolation window value. The baseline deviation is set to twice the average reconstruction error of the training samples used to calculate the reconstruction deviation. The preset isolation window value is set to 3 sampling points, corresponding to a time length of 30 seconds. All the above values are pre-calibrated and stored in the acquisition terminal.
[0073] When the calculated reconstruction deviation is greater than the preset tolerance threshold, the following anomaly identification and marking operations are performed.
[0074] First, calculate the difference between the original temperature value at each sampling point in the test data segment and the reconstructed temperature value at the corresponding position in the comparison data segment, forming a deviation difference sequence. Specifically, the test data segment contains 30 original temperature values arranged in chronological order, and the comparison data segment contains 30 reconstructed temperature values at corresponding positions. Subtract the reconstructed temperature value at the same position from each original temperature value to obtain 30 differences. These differences form a deviation difference sequence in chronological order. Each difference retains its positive or negative sign.
[0075] Second, using the deviation from the baseline as upper and lower bounds, sampling points with absolute values greater than the baseline deviation are selected from the deviation difference sequence and designated as candidate outliers. If a difference is positive and greater than the baseline deviation, or negative and its absolute value is greater than the baseline deviation, the sampling point corresponding to that difference is marked as a candidate outlier. The baseline deviation is a positive number, taking the value of twice the average reconstruction error of the aforementioned training samples; this value is typically between 0.1 and 0.3 degrees Celsius, with the specific value depending on the sensor's measurement accuracy and the stability of the cold chain environment. After this step, a subset of points meeting the criteria are selected from the 30 sampling points and are called candidate outliers.
[0076] Third, traverse the candidate outliers in chronological order, and count the sampling step size occupied by consecutive candidate outliers. Use this sampling step size as the number of consecutive sampling points exceeding the baseline. The traversal method is as follows: starting from the first sampling point of the data segment to be examined, check if the point is a candidate outlier; if so, start counting and continue checking the next sampling point until a non-candidate outlier is encountered or the end of the data segment is reached; record the value obtained from this consecutive count, which is the number of sampling points for a consecutive candidate outlier segment. Then, continue the above process from the next sampling point after the non-candidate outlier until all 30 sampling points have been traversed. Finally, several consecutive intervals are obtained, each interval corresponding to one number of sampling points.
[0077] Fourth, the number of sampling points in each continuous interval is compared with a preset isolated window value (i.e., 3). If the number of sampling points in a continuous interval is no more than 3, all sampling points in that interval are determined to be caused by a transient sensor fault, and these sampling points are marked as missing points. If the number of sampling points in a continuous interval is greater than 3, the continuous anomaly in that segment is determined to be likely caused by a real temperature change (such as a cold storage door opening or refrigeration failure), and is not treated as a transient fault, nor is it marked. Sampling points marked as missing points will no longer be considered valid data in subsequent steps, and their original temperature values will be reconstructed and replaced. The marking operation is implemented by maintaining a Boolean flag array in memory with the same length as the data segment to be tested. Each position corresponds to a sampling point, with positions marked as "missing" set to true and the rest set to false. After marking is completed, the Boolean flag array, along with the data segment to be tested, is passed to the next step.
[0078] In the missing site reconstruction and repair module, based on the unlabeled normal sites in the data segment to be examined, the temperature values of the missing sites are reconstructed using an overcomplete time series base library to obtain the repaired complete data segment, specifically including:
[0079] A Boolean flag array of the same length as the data segment to be tested was obtained, where each position marks whether the corresponding sampling point is a missing site (true value represents missing, false value represents normal). The data segment to be tested itself is a floating-point array containing 30 temperature values, arranged in chronological order. First, all normal sites not marked as missing sites are extracted from the data segment to be tested, along with their position indices in the original data segment (i.e., which sampling point). Specifically, each position in the Boolean flag array (from position 1 to position 30) is iterated. If the flag at that position is false, the temperature value at the same position in the data segment to be tested is retrieved, and the position index is recorded; if the flag is true, it is skipped. All retrieved temperature values are arranged in their original order to form a new sequence, called the incomplete observation sequence; simultaneously, the position index array corresponding to these temperature values is recorded, for example, normal sites appear at positions 1, 2, 4, 5, 7, etc. The length of the incomplete observation sequence is equal to the number of normal sites in the data segment to be tested, denoted as M. The M value depends on the severity of the transient fault and is typically between 27 and 30 (because the default isolation window value is 3, allowing for a maximum of 3 consecutive missing sites). Simultaneously, the location indices of all missing sites in the data segment to be examined are saved separately, forming a list of missing locations.
[0080] An overcomplete time-series basis library is a 30-row by 60-column matrix, where each column represents a basis vector (30 in length), and each row corresponds to one of the 30 sampling locations. To solve for sparse combination coefficients using normal sites in incomplete observation sequences, rows corresponding to the location indices of these normal sites need to be selected from the overcomplete time-series basis library to form a dimensionality-reduced basis library, called the dimensionality-reduced basis library.
[0081] The specific construction process is as follows:
[0082] The first step is to construct a binary selection vector of the same length as the data segment to be examined, based on the location indices of normal sites in the incomplete observation sequence. This vector has a length of 30, where elements corresponding to normal site locations are set to 1, and elements at other locations (i.e., missing site locations) are set to 0. For example, if the normal site locations are 1, 2, 4, and 5, then the 1st, 2nd, 4th, and 5th elements of the selection vector are 1, and the rest are 0.
[0083] The second step is to construct a 30-row by 30-column selection matrix using the binary selection vector as its diagonal elements. All off-diagonal elements of this matrix are 0, and the i-th element on the diagonal is equal to the i-th element of the binary selection vector. That is, only the diagonal positions corresponding to normal sites in the selection matrix are 1, and the rest are 0.
[0084] The third step involves left-multiplying the overcomplete time series library (30 rows by 60 columns) with the selection matrix to obtain a new matrix called the transition library. This transition library is also 30 rows by 60 columns, and each row is equal to a linear combination of the corresponding row in the selection matrix and the overcomplete time series library. Since each row of the selection matrix has only one non-zero element (located on the diagonal), the i-th row in the transition library is equal to the i-th row of the overcomplete time series library multiplied by the value of the i-th diagonal element of the selection matrix. If the i-th diagonal element of the selection matrix is 1, then the i-th row of the transition library is the same as the i-th row of the original overcomplete time series library; if it is 0, then all rows in the i-th row of the transition library are 0. Therefore, only the rows corresponding to normal sites retain the values of the original library in the transition library, while the rows corresponding to missing sites become all zero rows.
[0085] The fourth step involves deleting rows with all elements equal to zero from the transition base library, retaining the remaining non-zero rows to form the reduced-dimensional base library. The number of rows in the reduced-dimensional base library equals the number of normal loci, M, while the number of columns remains unchanged (still 60). Each row corresponds to the position index of a normal locus, and its column vector value is taken from the corresponding row in the original overcomplete time-series base library. The reduced-dimensional base library is essentially an M-row by 60-column matrix used for subsequent calculation of sparse combination coefficients.
[0086] After obtaining the reduced-dimensionality library (M rows by 60 columns) and the incomplete observation sequence (M in length), a set of sparse combination coefficients needs to be solved so that the incomplete observation sequence can be approximated by a linear combination of as few columns as possible in the reduced-dimensionality library. A variant of the orthogonal matching pursuit algorithm is used, with the following steps:
[0087] The combination coefficients are initialized as a zero vector of length 60. The incomplete observation sequence is used as the current residual vector, with a length of M. Two stopping conditions are preset: a maximum number of iterations of 5 (consistent with the preset maximum number of basis vectors), and the magnitude of the current residual is less than a preset convergence threshold. The magnitude of the current residual is calculated as follows: the squares of each element in the current residual vector are summed, and the square root of the sum is taken. The preset convergence threshold is the square root of 0.01 degrees Celsius multiplied by the number of normal sites M.
[0088] Start iteration:
[0089] First iteration: From the 60 columns of the dimensionality reduction library, find the column with the largest absolute value of its inner product with the current residual vector. The inner product is calculated by multiplying the corresponding positions of the column vector by the corresponding columns of the current residual vector and then summing the results. After finding the column, record its column index in the dimensionality reduction library and calculate the inner product of the column with the current residual vector. This inner product value is used as the increment of the combination coefficients for this iteration. Then, at the corresponding column index position in the combination coefficient vector, add the original weight (currently 0) to the increment of the combination coefficients to obtain the updated combination coefficients. Finally, subtract the result of "combination coefficient increment multiplied by the selected column" from the current residual vector to obtain the updated residual vector.
[0090] Second and subsequent iterations: Repeat the above process. Each time, find the column with the largest absolute value of the inner product with the current residual vector from the dimensionality reduction library (the same column can be selected repeatedly). Record the inner product value as the increment, update the combination coefficients, and update the residual vector. After each iteration, check the stopping condition: if the number of completed iterations reaches 5, or the magnitude of the current residual is less than the preset convergence threshold (e.g., 0.01 multiplied by the square root of M), then stop the iteration. The final accumulated combination coefficient vector of length 60 is the sparse combination coefficient.
[0091] It should be noted that, to ensure sparsity, this step does not require the selected column to be different from the previous one in each iteration, and allows the same column to be selected repeatedly. Furthermore, the number of non-zero elements in the final sparse combination coefficients is the actual number of iterations (maximum 5), achieving the goal of minimizing the number of basis vectors used.
[0092] After obtaining the sparse combination coefficients, it is necessary to reconstruct the temperature values of the missing sites. The specific steps are as follows:
[0093] From the overcomplete time series database (30 rows x 60 columns), extract the rows corresponding to the location indices of all missing sites to form a missing row matrix. The location indices of the missing sites are given by the missing location list in step (I). Let the number of missing sites be K (K ≤ 3), then the missing row matrix is a matrix of K rows x 60 columns, where each row corresponds to the location of a missing site in the original data segment, and its column vector values are taken from the values of the corresponding rows in the original overcomplete time series database.
[0094] The missing row matrix is linearly combined with the sparse combination coefficients (a column vector of length 60): each row of the missing row matrix is multiplied by the sparse combination coefficient vector (i.e., multiplied at corresponding positions and then summed), resulting in K values, each of which is the reconstruction temperature value of the corresponding missing site. Specifically, for the j-th missing site, the j-th row of its corresponding missing row matrix is taken, and each of the 60 elements of this row is multiplied by the 60 elements of the sparse combination coefficient vector. The 60 products are then summed to obtain the reconstruction temperature value of the missing site.
[0095] The K reconstructed temperature values are then filled into the corresponding missing sites in the data segment to be tested, one by one, according to the order in the missing site list. Meanwhile, the original normal site temperature values remain unchanged. The temperature values of all 30 sampling points are then recombine in their original order to obtain a new complete temperature data segment, called the repaired complete data segment. This data segment has the same length as the original data segment to be tested (30 sampling points), but the anomalous isolated points have been replaced by reconstructed values based on sparse representation, thus eliminating the erroneous effects of sensor transient faults.
[0096] In the process of solving the sparse combination coefficients described above, it is necessary to calculate the magnitude of the current residual vector. Let the current residual vector be: ;
[0097] in Given the number of normal sites, the modulus of the current residual is calculated using the following formula: ;
[0098] In the formula, Indicates the th element in the current residual vector. The value of each element, Indicates the number of normal sites. Indicates all The square root of the sum of the squares is then taken. This modulus is used to determine whether the convergence threshold has been reached.
[0099] Furthermore, when reconstructing the missing site, for the first... Each missing site has a reconstruction temperature value. Calculated using the following formula: ;
[0100] In the formula, Indicates the first in the overcomplete time series base library The row corresponding to the missing site is the first The element values of the column, Represents the sparse combination coefficient vector of the th The value of the nth element, 6060 is the total number of columns in the base library. This calculation will determine the nth element of the missing row matrix. The reconstructed value is obtained by multiplying the row and sparse combination coefficients by a dot product and summing them.
[0101] In the hash-based evidence storage and off-chain storage module, a data fingerprint is obtained by hashing the repaired complete data segment. This data fingerprint is then associated with a timestamp and device identifier and written to the blockchain network. Simultaneously, the original fault record and repair process metadata are stored off-chain and indexed. Specifically, this includes:
[0102] A hash operation is performed on the complete data segment to obtain the data fingerprint. Specifically, the secure hash algorithm SHA-256 is used. The 30 temperature values in the repaired complete data segment are arranged in their original order, with each temperature value retained to two decimal places. All values are converted into strings and concatenated as input. The resulting hash value, called the data fingerprint, is 64 hexadecimal characters long. Simultaneously, the timestamp of the current data acquisition terminal (accurate to milliseconds) and the device identifier of the corresponding temperature sensor (e.g., sensor serial number) are obtained.
[0103] The original fault records and repair process metadata generated in the anomaly identification and missing marker module and the missing site reconstruction and repair module need to be stored off-chain, and an indexable search directory should be established. The specific steps are as follows:
[0104] The original fault record and the metadata of the repair process are concatenated into an audit string in chronological order. The original fault record includes: sensor identifier (e.g., DS18B20_01), fault start time (i.e., the timestamp corresponding to the first sampling point marked as a missing site), original outlier sequence (i.e., the erroneous temperature values originally collected at the missing site, arranged in chronological order, with values separated by commas), and reconstructed value sequence (i.e., the replacement temperature values calculated in the missing site reconstruction and repair module, also arranged in chronological order, with values separated by commas). The metadata of the repair process includes: total number of iterations (i.e., the actual number of iterations performed in the missing site reconstruction and repair module when solving for sparse combination coefficients, ranging from 1 to 5), the magnitude of the final remaining residual (the specific value obtained according to the magnitude calculation method in the missing site reconstruction and repair module), and the position index of the selected basis vector (i.e., the column number selected from the dimensionality reduction basis library in each iteration, arranged in iteration order, with numbers separated by commas). All the above information is concatenated in the following order: first, the sensor identifier from the original fault record; then, the fault start time; next, the original outlier sequence; then, the reconstructed value sequence; then, the total number of iterations from the repair process metadata; then, the magnitude of the final remaining residual; and finally, the position index of the selected basis vector. Semicolons are used as separators between the fields to form a single string, called the first intermediate string.
[0105] The first intermediate string is subjected to a secondary hash to obtain the audit fingerprint. Specifically, the current timestamp and the device identifier of the current data acquisition terminal are concatenated at the beginning of the string using a vertical bar separator. The first intermediate string is then appended to this concatenation. An invisible control character (ASCII code 2 for the start of text and ASCII code 3 for the end of text) is added to both the beginning and end of the entire string to form the complete audit string. Two different hashing methods are applied to this audit string: first, the SHA-256 algorithm is used to calculate the hash value of the audit string, resulting in a 64-bit hexadecimal string as the intermediate hash result; then, the SHA-512 algorithm is used to perform a secondary hash operation on this intermediate hash result, ultimately yielding a hash value of 128 hexadecimal characters, called the audit fingerprint.
[0106] The audit fingerprint and data fingerprint are combined to generate a linked voucher. The combination method is as follows: the audit fingerprint and data fingerprint are directly concatenated in sequence, that is, the 128 characters of the audit fingerprint are written first, followed by the 64 characters of the data fingerprint, forming a string with a total length of 192 characters, which is called the linked voucher.
[0107] The associated credential is written to the blockchain network. Specifically, the notarization interface in the blockchain smart contract is invoked, and the associated credential, along with the current timestamp and device identifier, is packaged as the transaction payload and sent to the endorsing node of the consortium blockchain. After consensus is reached, the transaction is recorded in a block of the blockchain and stored within the same transaction record. This transaction record contains the transaction hash, timestamp, device identifier, and associated credential, which indirectly links to off-chain audit information.
[0108] The constructed audit string (i.e., a complete string with invisible control characters at the beginning and end) is stored in an off-chain storage area. This off-chain storage area utilizes a distributed file system (such as IPFS) or an enterprise-grade cloud database. After storage, a storage address is obtained, and the audit fingerprint is used as a unique index key to create a record in the local lookup directory. This record includes the mapping relationship between the audit fingerprint and the storage address. When it is necessary to verify the authenticity of a sensor fault handling process later, the off-chain audit string can be quickly located and read using the audit fingerprint. Its secondary hash value is then recalculated and compared with the audit fingerprint in the associated on-chain credential, thus confirming that the off-chain data has not been tampered with.
[0109] The working principle of this invention is as follows: Time-series data from temperature sensors are continuously collected during cold chain transportation, and a data segment to be tested is extracted using a fixed window length. This data segment is projected onto a pre-generated overcomplete time-series basis library. The minimum sparse coding coefficients are solved by iteratively selecting the basis vector with the largest inner product with the residual, and a comparison data segment is reconstructed. The reconstruction deviation between the two is calculated. When the reconstruction deviation exceeds a preset tolerance threshold, the number of consecutive sampling points in the data segment exceeding the baseline is identified. If this number is not greater than a preset isolated window value (e.g., 3 sampling points), it is determined to be a transient sensor fault, and the corresponding sampling points are marked as missing sites. Based on the unmarked normal positions... The system first solves for the sparse combination coefficients using a reduced-dimensional base library and an orthogonal matching pursuit algorithm. Then, it uses the rows corresponding to the missing sites in the overcomplete time-series base library and the sparse combination coefficients to perform a linear combination, reconstructing the temperature values of the missing sites and obtaining the repaired complete data segment. Finally, it performs a hash operation on the complete data segment to obtain a data fingerprint. The data fingerprint is then associated with a timestamp and device identifier and written into the blockchain network. At the same time, the original fault record and repair process metadata are concatenated into an audit string, which is then subjected to two different hash operations to obtain the audit fingerprint. The audit fingerprint and the data fingerprint are combined into an associated certificate and stored on the blockchain, while the audit string is stored off-chain and a search directory is established using the audit fingerprint as an index.
[0110] The foregoing has provided a detailed description of one embodiment of the present invention, but this description is merely a preferred embodiment and should not be construed as limiting the scope of the invention. All equivalent variations and modifications made within the scope of the claims of this invention should still fall within the patent coverage of this invention.
Claims
1. A blockchain-based food safety traceability information management system, characterized in that, include: The data acquisition and window capture module continuously acquires time-series data from temperature sensors during cold chain transportation and captures the current data segment as the data segment to be tested with a fixed window length. The sparse reconstruction and deviation calculation module projects the data segment to be tested onto a pre-generated overcomplete time series base library, solves for the minimum sparse coding coefficients, and reconstructs the comparison data segment based on the sparse coding coefficients to obtain the reconstruction deviation between the data segment to be tested and the comparison data segment. The anomaly identification and missing point marking module identifies the number of consecutive sampling points that deviate from the baseline in the data segment to be tested when the reconstruction deviation exceeds the preset tolerance threshold. If the number of sampling points is not greater than the preset isolated window value, it determines that there is a sensor transient fault and marks the sampling points as missing points. The missing site reconstruction and repair module reconstructs the temperature values of the missing sites based on the unlabeled normal sites in the data segment to be tested, and obtains the repaired complete data segment by using an overcomplete time series base library. The hash-based evidence storage and off-chain storage module performs hash operations on the repaired complete data segment to obtain a data fingerprint. After associating the data fingerprint with the timestamp and device identifier, it writes it into the blockchain network. At the same time, it stores the original fault record and repair process metadata off-chain and establishes an index.
2. The blockchain-based food safety traceability information management system according to claim 1, characterized in that, The reconstruction deviation specifically includes: The data segment to be tested is expressed as a linear combination of the basis vectors in the overcomplete time series basis library, and the maximum number of basis vectors used in the linear combination is preset. By iteratively selecting the basis vector with the largest inner product with the current remaining residual from the overcomplete time series basis library, and updating the linear combination coefficients, the number of selected basis vectors reaches the maximum number. The final obtained linear combination coefficients and corresponding basis vectors are used to construct a comparison data segment; Calculate the Euclidean norm of the difference between the data segment to be tested and the data segment to be compared, and use the Euclidean norm as the reconstruction deviation.
3. The blockchain-based food safety traceability information management system according to claim 2, characterized in that, The updating of linear combination coefficients specifically includes: Obtain the target basis vector selected from the overcomplete temporal basis library in the current iteration, and read the remaining residual from the previous round; Calculate the inner product of the target basis vector and the remaining residual from the previous round, and use the inner product as the current weight increment; The current weight increment is added to the original weights corresponding to the target basis vector in the linear combination coefficients to obtain the updated linear combination coefficients; The updated residual is obtained by subtracting the current weight increment multiplied by the target basis vector from the residual of the previous round, and then using it for the next iteration.
4. The blockchain-based food safety traceability information management system according to claim 1, characterized in that, The step of marking sampling points as missing sites specifically includes: Calculate the difference between the original temperature value of each sampling point in the data segment to be tested and the reconstructed temperature value at the corresponding position in the comparison data segment to form a deviation difference sequence; Using the deviation from the baseline as the upper and lower bounds, sampling points with an absolute value greater than the deviation from the baseline are selected from the deviation difference sequence and regarded as candidate outliers; Traverse the candidate outliers in chronological order, count the sampling step length occupied by consecutively occurring candidate outliers, and use the sampling step length as the number of consecutive sampling points that deviate from the baseline. The number of sampling points is compared with the preset isolated window value. When the number of sampling points is not greater than the preset isolated window value, the sampling points corresponding to the continuously appearing candidate abnormal points are determined to be caused by the sensor transient fault, and these sampling points are marked as missing sites.
5. The blockchain-based food safety traceability information management system according to claim 1, characterized in that, The process of obtaining the repaired complete data segment specifically includes: Extract all normal sites that are not marked as missing sites and their corresponding location indices from the data segment to be tested to form an incomplete observation sequence; From the incomplete time series base library, basis vector rows corresponding to the position indices in the incomplete observation sequence are selected to form a dimension-reduced base library; Solve for sparse combination coefficients that can linearly represent incomplete observation sequences in a reduced-dimensional basis library, while minimizing the number of basis vectors used; The sparse combination coefficients are linearly combined with the basis vector rows corresponding to the missing sites in the overcomplete time series base library to calculate the reconstruction temperature value of each missing site. The reconstruction temperature value is then filled into the corresponding position to obtain the repaired complete data segment.
6. The blockchain-based food safety traceability information management system according to claim 5, characterized in that, The aforementioned dimensionality reduction library specifically includes: Based on the location index of normal sites in the incomplete observation sequence, a binary selection vector of the same length as the data segment to be tested is constructed, where the element corresponding to the normal site is 1 and the other elements are zero. Construct a selection matrix with the binary selection vector as the diagonal element, and multiply the selection matrix by the complete temporal base library to obtain a transition base library with the same number of rows and columns. Remove all rows with zero elements from the transition base library and keep the remaining non-zero rows to form the reduced-dimensional base library.
7. The blockchain-based food safety traceability information management system according to claim 5, characterized in that, The process of solving for sparse combination coefficients in a reduced-dimensional library that can linearly represent incomplete observation sequences specifically includes: Initialize the combination coefficients to a zero vector and use the incomplete observation sequence as the current residual; Find the column with the largest absolute value of the inner product with the current residual from the reduced dimensionality library, select the corresponding column as the input column, and record the inner product value of the column as the combination coefficient increment; Subtract the combination coefficient increment multiplied by the selected result from the current residual to obtain the updated residual; Repeat the column selection and residual update process until the preset maximum number of iterations is reached or the magnitude of the current residual is less than the preset convergence threshold, and use the final accumulated combination coefficients as sparse combination coefficients.
8. The blockchain-based food safety traceability information management system according to claim 1, characterized in that, The index creation specifically includes: The original fault records and repair process metadata are concatenated into an audit string in chronological order, and the hash value of the audit string is calculated as the audit fingerprint. The audit fingerprint and data fingerprint are combined to generate a linked credential; Write the associated credentials into the blockchain network and store them in the same transaction record as the timestamp and device identifier; The audit string is stored in the off-chain storage area, and a search directory is established using the audit fingerprint as the unique index key.
9. The blockchain-based food safety traceability information management system according to claim 8, characterized in that, The calculation of the hash value of the audit string as the audit fingerprint specifically includes: The sensor identifier, fault start time, original anomaly value sequence and reconstructed value sequence in the original fault record are concatenated in a fixed order and separated by commas to form the first substring. The total number of iterations, the magnitude of the final remaining residual, and the position index of the selected basis vector in the metadata of the repair process are concatenated in another fixed order and separated by semicolons to form a second substring. The current timestamp, device identifier, first substring, and second substring are concatenated in sequence using vertical bar separators, and invisible control characters are added at the beginning and end to form the audit string; Two different hashing methods were applied to the audit string to obtain an intermediate hash result, and then a second hashing operation was performed on the intermediate hash result to obtain the audit fingerprint.