# Stream-DBSCAN: A Streaming Distributed Clustering Model for Water Quality Monitoring
## 3 Stream-DBSCAN Water Quality Detection Clustering Model
### Build the Model
In the case of the three data streams generated in process (3), the Stream-DBSCAN model employs three independent nodes to perform parallel operations on the data streams. Three tasks are set up in Flink to receive the KeyedStream generated after the partition. Each node is assigned a task, and the DBSCAN algorithm is utilized to cluster the dataset in each node. When the DBSCAN algorithm runs on each node, it chooses appropriate values of Eps and Minpts based on the number of data and the rate of change of the value. After the node completes the calculation task, the result is returned to the master node. At this point, the distributed clustering phase is complete. 5. The distributed clustering process generates three sets of clustered sub-results that need to be merged in this stage. To accomplish this, it is necessary to examine whether the boundaries of each cluster in the three clustering results produced by the DBSCAN algorithm can be merged. After receiving the three clustering results from the DBSCAN algorithm, the master node merges them as the final step in the entire Stream-DBSCAN model. The merge calculation for the entire dataset should be simple and efficient to maintain the processing speed of the entire model and prevent distributed computation from becoming meaningless. To effectively merge the clustering results from the three nodes and minimize the processing time, the Stream-DBSCAN model utilizes the overlapping and merging rule for clustering results, as shown in the figure below:  Figures 3a and 3b are the DBSCAN clustering results returned by computer nodes \(A\) and \(B\), respectively. 1. Calculate the centroid points of each cluster in Figure 3a,b, and obtain two centroids of \(A\) and \(B\). 2. Find the edge points closest to the centroid point of the other cluster in cluster \(A\) and cluster \(B\), respectively, as shown in Figure 3c, for two points \(a\) and \(b\). 3. Calculate the distances, \(L_{Ab}\) and \(L_{Ba}\) from the edge points in cluster \(A\) and cluster \(B\) to the centroid of another cluster (Figure 3c). 4. Compare the size relationship between \(L_{Ab}\), \(L_{Ba}\), and Eps, respectively, if \(L_{Ab}\), \(L_{Ba}\) < Eps, then merge the two clusters \(A\) and \(B\). The master node merges the clustering results of the three computer nodes according to the above-mentioned merging rules to obtain the final clustering result. 3. Calculate the distance between \(L_{Ab}\) and \(L_{Ba}\) from the edge points in cluster \(A\) and cluster \(B\) to the centroid of another cluster (Figure 3c). 4. Compare the size relationship between \(L_{Ab}\) and \(L_{Ba}\), and Eps, respectively, if \(L_{Ab}\), \(L_{Ba}\) < Eps, then merge the two clusters \(A\) and \(B\). The master node merges the clustering results of the three computer nodes according to the above-mentioned merging rules to obtain the final clustering result. 5  
The entire model process is illustrated by Figure 4.  
The Stream-DBSCAN clustering model facilitates parallel operation on three computing nodes during the clustering process for streaming data, resulting in a significant reduction in the clustering algorithm's running time. Additionally, the model implements overlapping merging as a rule to ensure the availability of clustering results. Using the Stream-DBSCAN clustering model, we obtained the clustering results of 200,000 water quality data, which consist of three factors: pH, NH4N, and turbidity. These factors affect the clustering results, whereas the time of non-influencing factors. The clustering process utilized the values of the three water quality indicators at a specific time point as a reference for clustering and merged similar water quality conditions corresponding to different times into one category. Therefore, analyzing the clustering results only requires referring to the time attribute in the clustering results.