mirror of
https://github.com/Hizenberg469/BPIT-ATTENDANCE.git
synced 2026-04-19 17:52:25 +03:00
initial commit
This commit is contained in:
10
shubham/html/Auth/Makefile
Normal file
10
shubham/html/Auth/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
TARGET: auth_exe
|
||||
auth_exe: auth.o main.o
|
||||
gcc auth.o main.o -o auth_exe `mysql_config --cflags --libs` -lm
|
||||
auth.o: auth.c
|
||||
gcc -c auth.c -o auth.o
|
||||
main.o: main.c
|
||||
gcc -c main.c -o main.o `mysql_config --cflags --libs`
|
||||
clean:
|
||||
rm auth.o
|
||||
rm main.o
|
||||
71
shubham/html/Auth/auth.c
Normal file
71
shubham/html/Auth/auth.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "auth.h"
|
||||
|
||||
|
||||
ld
|
||||
toRadians(ld degree){
|
||||
ld one_deg = (M_PI)/180;
|
||||
return (one_deg * degree);
|
||||
}
|
||||
|
||||
ld
|
||||
sq_root(ld value){
|
||||
ld err = 1e-10;
|
||||
|
||||
ld ans = 0;
|
||||
ld low = 0 , high = 0;
|
||||
|
||||
if(value < 1){
|
||||
low = value , high = 1;
|
||||
}
|
||||
else{
|
||||
low = 1 , high = value;
|
||||
}
|
||||
|
||||
for(int i = 1 ; i <= 67 ; i++ ){
|
||||
|
||||
ld mid = low + (high - low)/2.0;
|
||||
|
||||
if( mid*mid <= value ){
|
||||
ans = mid;
|
||||
low = mid + err;
|
||||
}
|
||||
else{
|
||||
high = mid - err;
|
||||
}
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
ld
|
||||
orthodromic_distance(ld stu_lat,ld stu_long,ld teach_lat,ld teach_long){
|
||||
stu_lat = toRadians(stu_lat);
|
||||
stu_long = toRadians(stu_long);
|
||||
teach_lat = toRadians(teach_lat);
|
||||
teach_long = toRadians(teach_long);
|
||||
|
||||
ld diff_lat = teach_lat - stu_lat;
|
||||
ld diff_long = teach_long - stu_long;
|
||||
|
||||
ld ans = pwr2(sin(diff_lat/2)) +
|
||||
cos(stu_lat) * cos(teach_lat) *
|
||||
pwr2(sin(diff_long/2));
|
||||
|
||||
ans = 2 * asin(sq_root(ans));
|
||||
|
||||
|
||||
// Radius of Earth in
|
||||
// Kilometers, R = 6371
|
||||
// Use R = 3956 for miles
|
||||
ld R = 6371;
|
||||
|
||||
//ans in meter...
|
||||
ans = ans * R * (ld)1000;
|
||||
return ans;
|
||||
}
|
||||
|
||||
bool
|
||||
check_range(ld dist){
|
||||
//better implementation for future....
|
||||
return dist <= (ld)100;
|
||||
}
|
||||
27
shubham/html/Auth/auth.h
Normal file
27
shubham/html/Auth/auth.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef __AUTH__
|
||||
#define __AUTH__
|
||||
|
||||
#ifndef _MATH_H_
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#define ld long double
|
||||
#define pwr2(x) (x * x)
|
||||
|
||||
ld
|
||||
sq_root(ld x);
|
||||
|
||||
ld
|
||||
toRadians( ld degree );
|
||||
|
||||
ld
|
||||
orthodromic_distance(ld stu_lat, ld stu_long, ld teach_lat, ld teach_long);
|
||||
|
||||
bool
|
||||
check_range(ld dist);
|
||||
|
||||
#endif // __AUTH__
|
||||
BIN
shubham/html/Auth/auth.o
Normal file
BIN
shubham/html/Auth/auth.o
Normal file
Binary file not shown.
BIN
shubham/html/Auth/auth_exe
Normal file
BIN
shubham/html/Auth/auth_exe
Normal file
Binary file not shown.
95
shubham/html/Auth/main.c
Normal file
95
shubham/html/Auth/main.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include <string.h>
|
||||
#include<mysql.h>
|
||||
#include "auth.h"
|
||||
|
||||
void
|
||||
error_found(MYSQL *con){
|
||||
printf("%s\n",mysql_error(con));
|
||||
mysql_close(con);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argv , char **argc){
|
||||
//Pass the Teacher latitude and longitude from command line argument.
|
||||
//Teacher latitude and longitude...
|
||||
ld teach_lat = strtold(argc[1],NULL) , teach_long = strtold(argc[2],NULL);
|
||||
|
||||
|
||||
MYSQL *con = mysql_init(NULL);
|
||||
|
||||
|
||||
if( con == NULL ){
|
||||
printf("mysql_init() failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( mysql_real_connect(con,"localhost","usr","admin@1224"
|
||||
,"bpitattendance", 0,NULL,0) == NULL ){
|
||||
error_found(con);
|
||||
}
|
||||
|
||||
if( mysql_query(con, "SELECT * FROM attendance") ){
|
||||
error_found(con);
|
||||
}
|
||||
|
||||
MYSQL_RES *result = mysql_store_result(con);
|
||||
|
||||
if( result == NULL ){
|
||||
error_found(con);
|
||||
}
|
||||
|
||||
int num_fields = mysql_num_fields(result);
|
||||
|
||||
MYSQL_ROW row;
|
||||
|
||||
// char *enroll;
|
||||
long double stu_lat = 0 , stu_long = 0;
|
||||
long double dist = 0;
|
||||
char en_num[15];
|
||||
char query[150]="";
|
||||
|
||||
while( (row = mysql_fetch_row(result) ) ){
|
||||
|
||||
|
||||
// printf("En:%s\n",row[0]);
|
||||
char enroll[12];
|
||||
strcpy(enroll,row[0]);
|
||||
|
||||
stu_lat = strtold(row[1],NULL);
|
||||
stu_long = strtold(row[2],NULL);
|
||||
|
||||
strcpy(query,"");
|
||||
sprintf(en_num,"%s",enroll);
|
||||
dist = orthodromic_distance(stu_lat,stu_long,teach_lat,teach_long);
|
||||
if( check_range(dist) ){
|
||||
strcat(query,"UPDATE attendance SET is_present = true WHERE enroll_num =\'");
|
||||
strcat(query,enroll);
|
||||
strcat(query,"\'");
|
||||
strcat(query,";");
|
||||
printf("Query: %s",query);
|
||||
if( mysql_query(con, query ) ){
|
||||
error_found(con);
|
||||
}
|
||||
printf("%s is present\n",enroll);
|
||||
}
|
||||
else{
|
||||
strcat(query,"UPDATE attendance SET is_present = false WHERE enroll_num =\'");
|
||||
strcat(query,enroll);
|
||||
strcat(query,"\'");
|
||||
strcat(query,";");
|
||||
printf("Query: %s",query);
|
||||
if( mysql_query(con,query ) ){
|
||||
error_found(con);
|
||||
}
|
||||
printf("%s is absent\n",enroll);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mysql_free_result(result);
|
||||
mysql_close(con);
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
shubham/html/Auth/main.o
Normal file
BIN
shubham/html/Auth/main.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user