Improved documentation.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Docker image / build (push) Successful in 1m8s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Docker image / build (push) Successful in 1m8s
				
			This commit is contained in:
		
							parent
							
								
									2844bd89d1
								
							
						
					
					
						commit
						666bf5700e
					
				
					 1 changed files with 26 additions and 1 deletions
				
			
		
							
								
								
									
										27
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -14,9 +14,34 @@ import (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
// Payload struct
 | 
			
		||||
// Dt1, Dt2, Rt1, Rt2 and G are meter readings
 | 
			
		||||
//
 | 
			
		||||
// All metrics are stored in PostgreSQL as INT and not NUMERIC or FLOAT to optimise their storage size.
 | 
			
		||||
//
 | 
			
		||||
// Dt1, Dt2, Rt1, Rt2 and G are cumulative meter readings.
 | 
			
		||||
// By making them pointers to int, they can be set to 'nil' when the reading has not changed.
 | 
			
		||||
// This way, they are logged as NULL in the database when no change has happened, saving storage capacity.
 | 
			
		||||
// As an added benefit, this also make data retrieval, visualisation and analysis more light-weight.
 | 
			
		||||
//
 | 
			
		||||
// Gas consumption is updated once per minute.
 | 
			
		||||
// Not saving intermittent values theoretically saves 4 bytes per value.
 | 
			
		||||
//   Storage for non-NULL values every second:
 | 
			
		||||
//     86,400 entries/day×4 bytes/entry=345,600 bytes/day86,400entries/day×4bytes/entry=345,600bytes/day
 | 
			
		||||
//   Storage for non-NULL values every minute:
 | 
			
		||||
//     1,440 entries/day×4 bytes/entry=5,760 bytes/day1,440entries/day×4bytes/entry=5,760bytes/day
 | 
			
		||||
//   Storage savings:
 | 
			
		||||
//     345,600 bytes/day−5,760 bytes/day=339,840 bytes/day345,600bytes/day−5,760bytes/day=339,840bytes/day
 | 
			
		||||
//     (about 331.5 KB / day or 9.72 MB / month)
 | 
			
		||||
//   In practice, savings will be even higher when gas is not being consumed continuously.
 | 
			
		||||
//
 | 
			
		||||
// When Tariff 1 is active, Tariff 2 isn't.
 | 
			
		||||
//   Therefore, only updating their values on-change should at least half their storage capacity requirements
 | 
			
		||||
//   An average month has 2 629 743.83 seconds.
 | 
			
		||||
//   This saves at least:
 | 
			
		||||
//     2,629,743.83 seconds * 4 bytes = 10,518,975.32 bytes = 10,518.98 kB = 10.52 MB
 | 
			
		||||
//   This applies both to Dt1 and Dt2 as well as Rt1 and Rt2, so should be doubled.
 | 
			
		||||
//     10.52 * 2 = 21.04 MB.
 | 
			
		||||
//   In practice, savings will be even higher when electricity is not being consumed continuously.
 | 
			
		||||
 | 
			
		||||
type Payload struct {
 | 
			
		||||
	T   string `json:"t"`   // Timestamp
 | 
			
		||||
	Dt1 *int   `json:"dt1"` // Delivered / imported meter reading tariff 1 (kWh)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue