Depronto Infotech

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Tripura Suryawanshi

[email protected]
7798640168

DBMS
create table Contests(

contest_id integer, --- primary key

hacker_id integer,

name varchar2(50)

);

create table Colleges

college_id integer, --- college id--

contest_id integer

);

create table challenges

challenge_id integer, --- primary key

college_id integer

);

create table view_stats(

challenge_id integer,

total_views integer,
total_unique_views integer

);

create table submission_stats

challenge_id integer,

total_submission integer,

total_accepted_submissions integer

);

-- adding primary keys

alter table Contests

add constraint C_pk1 primary key (contest_id );

alter table Colleges

add constraint C_pk2 primary key ( college_id );

alter table challenges

add constraint C_pk3 primary key (challenge_id );

--- foreign keys----

alter table challenges

add constraint c_FK1 Foreign key

( college_id)references

Colleges( college_id);

alter table colleges

add constraint c_FK2 Foreign key

( contest_id)references
Contests( contest_id);

alter table submission_stats

add constraint c_FK4 Foreign key

( challenge_id)references

challenges( challenge_id);

---- inserting values in table

INSERT INTO Contests (contest_id, hacker_id, name)

VALUES(1, 101, 'Weekly Coding Challenge');

INSERT INTO Contests (contest_id, hacker_id, name) VALUES (2, 102, 'Monthly Hackathon');

INSERT INTO Contests (contest_id, hacker_id, name) VALUES (3, 103, 'Algorithms Competition');

-- Colleges table

INSERT INTO Colleges (college_id, contest_id) VALUES (1, 1);

INSERT INTO Colleges (college_id, contest_id) VALUES (2, 2);

INSERT INTO Colleges (college_id, contest_id) VALUES (3, 3);

-- Challenges table

INSERT INTO Challenges (challenge_id, college_id) VALUES (101, 1);

INSERT INTO Challenges (challenge_id, college_id) VALUES (102, 2);

INSERT INTO Challenges (challenge_id, college_id) VALUES (103, 3);

-- view_stats table

INSERT INTO view_stats (challenge_id, total_views, total_unique_views) VALUES (101, 100, 50);

INSERT INTO view_stats (challenge_id, total_views, total_unique_views) VALUES (102, 150, 80);

INSERT INTO view_stats (challenge_id, total_views, total_unique_views) VALUES (103, 120, 60);

-- submission_stats table
INSERT INTO submission_stats (challenge_id, total_submission, total_accepted_submissions)
VALUES (101, 80, 70);

INSERT INTO submission_stats (challenge_id, total_submission, total_accepted_submissions)


VALUES (102, 120, 100);

INSERT INTO submission_stats (challenge_id, total_submission, total_accepted_submissions)


VALUES (103, 90, 80);

select * from Contests;


SELECT c.contest_id, c.hacker_id, c.name,

SUM(s.total_submissions) AS total_submissions,

SUM(s.total_accepted_submissions) AS total_accepted_submissions,

SUM(v.total_views) AS total_views,

SUM(v.total_unique_views) AS total_unique_views

FROM Contests c

JOIN Colleges clg ON c.contest_id = clg.contest_id

JOIN Challenges ch ON clg.college_id = ch.college_id

LEFT JOIN SubmissionStats s ON ch.challenge_id = s.challenge_id

LEFT JOIN ViewStats v ON ch.challenge_id = v.challenge_id

GROUP BY c.contest_id, c.hacker_id, c.name

HAVING SUM(s.total_submissions) > 0

OR SUM(s.total_accepted_submissions) > 0

OR SUM(v.total_views) > 0

OR SUM(v.total_unique_views) > 0
ORDER BY c.contest_id;

1. Frontent
/**
Challenge: Pressing `Increment` button should increase the counter count by one.
Pressing `Decrement` button should decrease the counter count by one.
**/
const App = () => {
const [count, setCount] = React.useState(0);

const increment = () => {


setCount(count + 1);
};

const decrement = () => {


setCount(count - 1);
};

return (
<div>
<h2>Counter: {count}</h2>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
};

ReactDOM.render(<App />, document.getElementById("root"));

Css
div {
padding: 10px;
}
button {
margin: 10px 0;
padding: 5px 10px;
}
input {
display: block;
padding: 5px;
margin-bottom: 5px;
width: 120px;
}

Html
<div id="root"></div>
Php
<?php
// Check if user is logged in, otherwise redirect to login page
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
exit;
}

// Function to validate login credentials


function validate_login($username, $password) {
// In a real-world scenario, you'd check against a database
$valid_users = array(
'admin' => 'password123',
// Add more users as needed
);

// Check if username exists and password matches


if (array_key_exists($username, $valid_users) && $valid_users[$username]
=== $password) {
return true;
} else {
return false;
}
}

// Function to handle exceptions


function customExceptionHandler($exception) {
// Log the error to a file or database
file_put_contents('error.log', $exception->getMessage(), FILE_APPEND);
// Display a friendly error message to the user
echo "An error occurred. Please try again later.";
}

// Set custom exception handler


set_exception_handler('customExceptionHandler');

// Read product data from JSON file


$products_json = file_get_contents('products.json');
$products = json_decode($products_json, true);

// Display product catalog


foreach ($products as $product) {
echo "<div class='product'>";
echo "<img src='{$product['image']}' alt='{$product['name']}'><br>";
echo "<h2>{$product['name']}</h2>";
echo "<p>Price: {$product['price']}</p>";
echo "</div>";
}
?>

Login
<?php
session_start();

// Check if the form is submitted


if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];

// Validate login credentials


if (validate_login($username, $password)) {
// Set session variables
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
// Redirect user to the catalog page
header("Location: catalog.php");
} else {
// Display error message if credentials are invalid
$login_err = "Invalid username or password";
}
}

// Function to validate login credentials


function validate_login($username, $password) {
// In a real-world scenario, you'd check against a database
$valid_users = array(
'admin' => 'password123',
// Add more users as needed
);

// Check if username exists and password matches


if (array_key_exists($username, $valid_users) && $valid_users[$username]
=== $password) {
return true;
} else {
return false;
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br>
<input type="submit" value="Login">
</form>
<?php if(isset($login_err)) echo "<p style='color:red;'>$login_err</p>"; ?
>
</body>
</html>

Json
[
{
"name": "Product 1",
"price": "$10",
"image": "product1.jpg"
},
{
"name": "Product 2",
"price": "$20",
"image": "product2.jpg"
},
{
"name": "Product 3",
"price": "$30",
"image": "product3.jpg"
}
]

java
import java.util.List;
import java.util.stream.Collectors;
public class ParallelStreamExample {
public static void main(String[] args) {
// Initialize a list of data
List<Integer> numbers = List.of(1, 2, 3, 4,
5, 6, 7, 8, 9, 10);

// Create parallel stream and perform


operations
List<Integer> result =
numbers.parallelStream()
.filter(num -> num % 2
== 0) // Filter even numbers
.map(num -> num *
num) // Square the numbers
.collect(Collectors.toList
()); // Collect the results

// Print the result


System.out.println(result);
}
}
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import
java.util.concurrent.atomic.AtomicInteger;

public class ConcurrentTextAnalysis {


private static final int NUM_THREADS =
4; // Number of threads

public static void main(String[] args) {


Map<String, Integer> wordCount = new
HashMap<>();
ExecutorService executor =
Executors.newFixedThreadPool(NUM_THREA
DS);

try (BufferedReader reader = new


BufferedReader(new
FileReader("large_text_file.txt"))) {
String line;
while ((line = reader.readLine()) !=
null) {
executor.execute(() ->
processLine(line, wordCount));
}
} catch (IOException e) {
e.printStackTrace();
}

executor.shutdown();
while (!executor.isTerminated()) {}

// Combine the results from all threads


System.out.println(wordCount);
}

private static void processLine(String line,


Map<String, Integer> wordCount) {
String[] words = line.split("\\s+"); //
Split line into words
for (String word : words) {
synchronized (wordCount) {
wordCount.put(word,
wordCount.getOrDefault(word, 0) + 1); //
Update word count
}
}
}
}

You might also like