presudo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ src/data/destinations.js
2
+
3
+ This file will hold the data for destinations.
4
+
5
+ export const destinations = [
6
+ { id: 1, name: "Paris", country: "France", x: 100, y: 200, description: "City of light" },
7
+ { id: 2, name: "New York", country: "USA", x: 300, y: 100, description: "The Big Apple" },
8
+ { id: 3, name: "Tokyo", country: "Japan", x: 500, y: 300, description: "City of technology" },
9
+ // Add more destinations here
10
+ ];
11
+
12
+
13
+ -----------------------------------------------------------------------------------------------------------------------------------
14
+
15
+ src/components/FilterBar.jsx
16
+
17
+ The filter bar to filter destinations based on selected country.
18
+
19
+ import React from "react";
20
+
21
+ const FilterBar = ({ countries, selectedCountry, onChange }) => {
22
+ return (
23
+ <div style={{ marginBottom: "10px" }}>
24
+ <select value={selectedCountry} onChange={onChange}>
25
+ <option value="">All Countries</option>
26
+ {countries.map((country) => (
27
+ <option key={country} value={country}>
28
+ {country}
29
+ </option>
30
+ ))}
31
+ </select>
32
+ </div>
33
+ );
34
+ };
35
+
36
+ export default FilterBar;
37
+
38
+ -----------------------------------------------------------------------------------------------------------------------------------
39
+
40
+ src/components/DestinationCard.jsx
41
+
42
+ Card component to display individual destinations.
43
+
44
+ import React from "react";
45
+
46
+ const DestinationCard = ({ destination, isActive, onSelect }) => {
47
+ return (
48
+ <div
49
+ onClick={() => onSelect(destination)}
50
+ style={{
51
+ border: "1px solid #ccc",
52
+ padding: "10px",
53
+ marginBottom: "8px",
54
+ cursor: "pointer",
55
+ backgroundColor: isActive ? "#e0f7fa" : "#fff",
56
+ }}
57
+ >
58
+ <h4>{destination.name}</h4>
59
+ <p>{destination.country}</p>
60
+ </div>
61
+ );
62
+ };
63
+
64
+ export default DestinationCard;
65
+
66
+ -----------------------------------------------------------------------------------------------------------------------------------
67
+
68
+ src/components/DestinationList.jsx
69
+
70
+ This component renders the list of destinations.
71
+
72
+ import React from "react";
73
+ import DestinationCard from "./DestinationCard";
74
+
75
+ const DestinationList = ({ destinations, selected, onSelect }) => {
76
+ return (
77
+ <div>
78
+ {destinations.map((dest) => (
79
+ <DestinationCard
80
+ key={dest.id}
81
+ destination={dest}
82
+ isActive={selected?.id === dest.id}
83
+ onSelect={onSelect}
84
+ />
85
+ ))}
86
+ </div>
87
+ );
88
+ };
89
+
90
+ export default DestinationList;
91
+
92
+ -----------------------------------------------------------------------------------------------------------------------------------
93
+
94
+
95
+ src/components/MapView.jsx
96
+
97
+ This component will display the map with destinations.
98
+
99
+ import React from "react";
100
+
101
+ const MapView = ({ destinations, selected, onSelect }) => {
102
+ return (
103
+ <div
104
+ style={{
105
+ position: "relative",
106
+ height: "400px",
107
+ backgroundColor: "#eef",
108
+ border: "1px solid #aaa",
109
+ }}
110
+ >
111
+ {destinations.map((dest) => (
112
+ <div
113
+ key={dest.id}
114
+ onClick={() => onSelect(dest)}
115
+ title={dest.name}
116
+ style={{
117
+ position: "absolute",
118
+ left: dest.x,
119
+ top: dest.y,
120
+ width: "12px",
121
+ height: "12px",
122
+ borderRadius: "50%",
123
+ backgroundColor: selected?.id === dest.id ? "red" : "blue",
124
+ cursor: "pointer",
125
+ }}
126
+ />
127
+ ))}
128
+
129
+ {selected && (
130
+ <div
131
+ style={{
132
+ position: "absolute",
133
+ bottom: "10px",
134
+ left: "10px",
135
+ background: "#fff",
136
+ padding: "10px",
137
+ border: "1px solid #ccc",
138
+ }}
139
+ >
140
+ <strong>{selected.name}</strong>
141
+ <p>{selected.description}</p>
142
+ </div>
143
+ )}
144
+ </div>
145
+ );
146
+ };
147
+
148
+ export default MapView;
149
+
150
+
151
+ -----------------------------------------------------------------------------------------------------------------------------------
152
+
153
+ src/App.js
154
+
155
+ The main app component, handling state and rendering components.
156
+
157
+ import React, { useState, useEffect, useMemo } from "react";
158
+ import { destinations as data } from "./data/destinations";
159
+ import DestinationList from "./components/DestinationList";
160
+ import MapView from "./components/MapView";
161
+ import FilterBar from "./components/FilterBar";
162
+
163
+ const App = () => {
164
+ const [destinations, setDestinations] = useState([]);
165
+ const [selectedDestination, setSelectedDestination] = useState(null);
166
+ const [selectedCountry, setSelectedCountry] = useState("");
167
+
168
+ // Load data on mount
169
+ useEffect(() => {
170
+ setDestinations(data);
171
+ }, []);
172
+
173
+ // Extract unique countries
174
+ const countries = useMemo(() => {
175
+ return [...new Set(destinations.map((d) => d.country))];
176
+ }, [destinations]);
177
+
178
+ // Filter destinations
179
+ const filteredDestinations = useMemo(() => {
180
+ if (!selectedCountry) return destinations;
181
+ return destinations.filter((d) => d.country === selectedCountry);
182
+ }, [destinations, selectedCountry]);
183
+
184
+ return (
185
+ <div style={{ display: "flex", padding: "20px", gap: "20px" }}>
186
+ {/* Sidebar */}
187
+ <div style={{ width: "30%" }}>
188
+ <h2>Travel Destinations</h2>
189
+ <FilterBar
190
+ countries={countries}
191
+ selectedCountry={selectedCountry}
192
+ onChange={(e) => setSelectedCountry(e.target.value)}
193
+ />
194
+ <DestinationList
195
+ destinations={filteredDestinations}
196
+ selected={selectedDestination}
197
+ onSelect={setSelectedDestination}
198
+ />
199
+ </div>
200
+ {/* Map */}
201
+ <div style={{ width: "70%" }}>
202
+ <MapView
203
+ destinations={filteredDestinations}
204
+ selected={selectedDestination}
205
+ onSelect={setSelectedDestination}
206
+ />
207
+ </div>
208
+ </div>
209
+ );
210
+ };
211
+
212
+ export default App;
@@ -0,0 +1,217 @@
1
+ //(Returns all students with the highest score for each exam)
2
+
3
+ SELECT exam_id, student_id, student_name, score
4
+ FROM (
5
+ SELECT
6
+ s.*,
7
+ RANK() OVER (PARTITION BY exam_id ORDER BY score DESC) AS rnk
8
+ FROM scores AS s
9
+ ) AS ranked
10
+ WHERE rnk = 1
11
+ ORDER BY exam_id, student_name;
12
+
13
+ ---------------------------------------------------------------------------------------------------------------------------------------------
14
+
15
+
16
+
17
+ //(Top scorer per subject)
18
+
19
+ SELECT subject_id, student_id, student_name, score
20
+ FROM (
21
+ SELECT
22
+ subject_id, student_id, student_name, score,
23
+ RANK() OVER (PARTITION BY subject_id ORDER BY score DESC) AS rnk
24
+ FROM scores
25
+ ) AS ranked
26
+ WHERE rnk = 1
27
+ ORDER BY subject_id, student_name;
28
+
29
+ ---------------------------------------------------------------------------------------------------------------------------------------------
30
+
31
+
32
+
33
+ 1. Basic Query with Sorting and LIMIT
34
+
35
+ SQL Query: Top Scorer (Simple Sorting)
36
+
37
+ SELECT name, marks
38
+ FROM students
39
+ ORDER BY marks DESC
40
+ LIMIT 1;
41
+
42
+ Explanation:
43
+
44
+ Sorting: Sorts students by marks in descending order to get the highest scorer.
45
+
46
+ Data Filtering: Filters for the top scorer.
47
+
48
+ SQL Syntax: The query is simple, using basic SQL keywords.
49
+ ---------------------------------------------------------------------------------------------------------------------------------------------
50
+
51
+ 2. Top Scorer Using Subquery
52
+
53
+ SQL Query: Top Scorer Using Subquery
54
+
55
+ SELECT name, marks
56
+ FROM students
57
+ WHERE marks = (SELECT MAX(marks) FROM students);
58
+
59
+ Explanation:
60
+
61
+ Data Filtering: Filters students whose marks match the maximum marks in the dataset.
62
+
63
+ Unique Values: Ensures the top scorer(s) are unique by selecting only those with the highest marks.
64
+
65
+ SQL Syntax: Uses a subquery to identify the top marks.
66
+ ---------------------------------------------------------------------------------------------------------------------------------------------
67
+
68
+ 3. Sorting and Getting Multiple Top Scorers (Handling Ties)
69
+
70
+ SQL Query: Top Scorers with Ties
71
+
72
+ SELECT name, marks
73
+ FROM students
74
+ WHERE marks = (SELECT MAX(marks) FROM students)
75
+ ORDER BY marks DESC;
76
+
77
+ Explanation:
78
+
79
+ Sorting: Sorts the students by marks in descending order.
80
+
81
+ Data Filtering: Filters students who have the highest marks.
82
+
83
+ Unique Values: If there are multiple top scorers with the same marks, all are returned.
84
+ ---------------------------------------------------------------------------------------------------------------------------------------------
85
+
86
+ 4. Using RANK() for Tied Top Scorers
87
+
88
+ SQL Query: Top Scorer(s) with Ranking
89
+
90
+ WITH RankedStudents AS (
91
+ SELECT name, marks, RANK() OVER (ORDER BY marks DESC) AS rank
92
+ FROM students
93
+ )
94
+ SELECT name, marks
95
+ FROM RankedStudents
96
+ WHERE rank = 1;
97
+
98
+ Explanation:
99
+
100
+ Sorting: The RANK() function sorts students by marks.
101
+
102
+ Data Filtering: Filters the students with rank = 1 (the top scorers).
103
+
104
+ Unique Values: Handles ties by ranking multiple students with the same marks.
105
+ ---------------------------------------------------------------------------------------------------------------------------------------------
106
+
107
+ 5. Using DENSE_RANK() for Continuous Ranking
108
+
109
+ SQL Query: Top Scorer(s) with Continuous Rank
110
+
111
+ WITH RankedStudents AS (
112
+ SELECT name, marks, DENSE_RANK() OVER (ORDER BY marks DESC) AS rank
113
+ FROM students
114
+ )
115
+ SELECT name, marks
116
+ FROM RankedStudents
117
+ WHERE rank = 1;
118
+
119
+ Explanation:
120
+
121
+ Sorting: DENSE_RANK() assigns a rank with no gaps between tied students.
122
+
123
+ Data Filtering: Filters the top scorer(s) with rank = 1.
124
+
125
+ SQL Syntax: DENSE_RANK() is used to handle ties by giving all students with the same marks the same rank.
126
+ ---------------------------------------------------------------------------------------------------------------------------------------------
127
+
128
+ 6. Using LIMIT to Get Only One Top Scorer
129
+
130
+ SQL Query: Top Scorer with LIMIT
131
+
132
+ SELECT name, marks
133
+ FROM students
134
+ ORDER BY marks DESC
135
+ LIMIT 1;
136
+
137
+ Explanation:
138
+
139
+ Sorting: Sorts students by marks in descending order.
140
+
141
+ SQL Syntax: LIMIT 1 ensures that only the top scorer is returned.
142
+ ---------------------------------------------------------------------------------------------------------------------------------------------
143
+
144
+ 7. Using HAVING with GROUP BY for Top Scorer by Department
145
+
146
+ SQL Query: Top Scorer by Department
147
+
148
+ SELECT department, name, marks
149
+ FROM students
150
+ GROUP BY department
151
+ HAVING marks = (SELECT MAX(marks) FROM students WHERE department = students.department);
152
+
153
+ Explanation:
154
+
155
+ Data Filtering: Filters the top scorer in each department using a HAVING clause.
156
+
157
+ Sorting: Implicitly sorted by the GROUP BY department.
158
+
159
+ Unique Values: Filters to only include the top scorer from each department.
160
+ ---------------------------------------------------------------------------------------------------------------------------------------------
161
+
162
+ 8. Using DISTINCT to Ensure Unique Top Scorers
163
+
164
+ SQL Query: Distinct Top Scorers
165
+
166
+ SELECT DISTINCT name, marks
167
+ FROM students
168
+ WHERE marks = (SELECT MAX(marks) FROM students);
169
+
170
+ Explanation:
171
+
172
+ Unique Values: The DISTINCT keyword ensures only unique top scorers are returned.
173
+
174
+ Data Filtering: Filters students with the highest marks from the dataset.
175
+
176
+ Sorting: No explicit sorting needed, but ensures uniqueness.
177
+ ---------------------------------------------------------------------------------------------------------------------------------------------
178
+
179
+ 9. Top Scorer Identification with ROW_NUMBER()
180
+
181
+ SQL Query: Top Scorer Using ROW_NUMBER()
182
+
183
+ WITH RankedStudents AS (
184
+ SELECT name, marks, ROW_NUMBER() OVER (ORDER BY marks DESC) AS rank
185
+ FROM students
186
+ )
187
+ SELECT name, marks
188
+ FROM RankedStudents
189
+ WHERE rank = 1;
190
+
191
+ Explanation:
192
+
193
+ Sorting: ROW_NUMBER() sorts students by marks in descending order.
194
+
195
+ Data Filtering: Filters the rank 1 student(s) (the top scorer).
196
+
197
+ Unique Values: The function ROW_NUMBER() ensures each student is assigned a unique rank.
198
+ ---------------------------------------------------------------------------------------------------------------------------------------------
199
+
200
+ 10. Using MAX() with GROUP BY for Top Scorer Per City
201
+
202
+ SQL Query: Top Scorer Per City
203
+
204
+ SELECT city, name, marks
205
+ FROM students s
206
+ WHERE marks = (
207
+ SELECT MAX(marks) FROM students WHERE city = s.city
208
+ )
209
+ GROUP BY city;
210
+
211
+ Explanation:
212
+
213
+ Data Filtering: The subquery filters the top marks for each city.
214
+
215
+ Sorting: The query does not explicitly sort, but GROUP BY is used to group results by city.
216
+
217
+ Unique Values: Ensures each city has its top scorer listed uniquely.
@@ -0,0 +1,135 @@
1
+ 1. Product.ts
2
+
3
+ This file defines the Product class, which represents a product in the store. The Product class includes methods for updating stock and displaying product details.
4
+
5
+ // Product.ts
6
+ export class Product {
7
+ productId: string;
8
+ name: string;
9
+ price: number;
10
+ stock: number;
11
+
12
+ constructor(productId: string, name: string, price: number, stock: number) {
13
+ this.productId = productId;
14
+ this.name = name;
15
+ this.price = price;
16
+ this.stock = stock;
17
+ }
18
+
19
+ // Update product stock after a sale
20
+ updateStock(amountSold: number): void {
21
+ if (this.stock >= amountSold) {
22
+ this.stock -= amountSold;
23
+ console.log(`${this.name}: Sold ${amountSold} items. Remaining stock: ${this.stock}`);
24
+ } else {
25
+ console.log(`${this.name}: Not enough stock available.`);
26
+ }
27
+ }
28
+
29
+ // Display product details
30
+ displayProduct(): void {
31
+ console.log(`Product ID: ${this.productId}`);
32
+ console.log(`Name: ${this.name}`);
33
+ console.log(`Price: $${this.price}`);
34
+ console.log(`Stock: ${this.stock}`);
35
+ }
36
+
37
+ // Check if product is in stock
38
+ isInStock(amountSold: number): boolean {
39
+ return this.stock >= amountSold;
40
+ }
41
+ }
42
+
43
+ 2. ProductManager.ts
44
+
45
+ This file defines the ProductManager class, which handles product inventory operations such as adding products, updating stock, and displaying all products.
46
+
47
+ // ProductManager.ts
48
+ import { Product } from './Product';
49
+
50
+ export class ProductManager {
51
+ private products: Product[] = [];
52
+
53
+ // Add a new product to the inventory
54
+ addProduct(product: Product): void {
55
+ this.products.push(product);
56
+ console.log(`${product.name} added to the inventory.`);
57
+ }
58
+
59
+ // Display all products in the inventory
60
+ displayAllProducts(): void {
61
+ if (this.products.length === 0) {
62
+ console.log("No products available.");
63
+ } else {
64
+ console.log("\n--- Available Products ---");
65
+ this.products.forEach((product) => product.displayProduct());
66
+ }
67
+ }
68
+
69
+ // Search for a product by its ID
70
+ findProductById(productId: string): Product | undefined {
71
+ return this.products.find((product) => product.productId === productId);
72
+ }
73
+
74
+ // Search for a product by its name
75
+ findProductByName(productName: string): Product | undefined {
76
+ return this.products.find((product) => product.name.toLowerCase() === productName.toLowerCase());
77
+ }
78
+
79
+ // Update stock after a sale
80
+ processSale(productId: string, quantity: number): void {
81
+ const product = this.findProductById(productId);
82
+ if (product) {
83
+ if (product.isInStock(quantity)) {
84
+ product.updateStock(quantity);
85
+ } else {
86
+ console.log(`Not enough stock of ${product.name}.`);
87
+ }
88
+ } else {
89
+ console.log("Product not found.");
90
+ }
91
+ }
92
+
93
+ // Generate inventory report
94
+ generateInventoryReport(): void {
95
+ console.log("\n--- Inventory Report ---");
96
+ this.products.forEach((product) => product.displayProduct());
97
+ }
98
+ }
99
+
100
+ 3. Main.ts
101
+
102
+ This file is the entry point where we interact with the ProductManager to manage products, process sales, and generate reports.
103
+
104
+ // Main.ts
105
+ import { Product } from './Product';
106
+ import { ProductManager } from './ProductManager';
107
+
108
+ // Create an instance of the ProductManager
109
+ const manager = new ProductManager();
110
+
111
+ // Create some products
112
+ const product1 = new Product("P001", "Laptop", 1000, 50);
113
+ const product2 = new Product("P002", "Smartphone", 700, 100);
114
+ const product3 = new Product("P003", "Headphones", 150, 200);
115
+
116
+ // Add products to the inventory
117
+ manager.addProduct(product1);
118
+ manager.addProduct(product2);
119
+ manager.addProduct(product3);
120
+
121
+ // Display all products in the inventory
122
+ manager.displayAllProducts();
123
+
124
+ // Process sales for the products
125
+ manager.processSale("P001", 5); // Selling 5 Laptops
126
+ manager.processSale("P002", 3); // Selling 3 Smartphones
127
+
128
+ // Display updated product list after sales
129
+ manager.displayAllProducts();
130
+
131
+ // Generate an inventory report
132
+ manager.generateInventoryReport();
133
+
134
+ // Attempting to sell more than available stock
135
+ manager.processSale("P003", 250); // Trying to sell 250 Headphones (more than stock)
@@ -0,0 +1,113 @@
1
+ // RetailStore.ts
2
+
3
+ class Product {
4
+ productId: string;
5
+ name: string;
6
+ price: number;
7
+ stock: number;
8
+
9
+ constructor(productId: string, name: string, price: number, stock: number) {
10
+ this.productId = productId;
11
+ this.name = name;
12
+ this.price = price;
13
+ this.stock = stock;
14
+ }
15
+
16
+ // Method to update the stock after a sale
17
+ updateStock(amountSold: number): void {
18
+ if (this.stock >= amountSold) {
19
+ this.stock -= amountSold;
20
+ console.log(`${this.name}: Sold ${amountSold} items. Remaining stock: ${this.stock}`);
21
+ } else {
22
+ console.log(`${this.name}: Not enough stock available.`);
23
+ }
24
+ }
25
+
26
+ // Method to display product details
27
+ displayProduct(): void {
28
+ console.log(`Product ID: ${this.productId}`);
29
+ console.log(`Name: ${this.name}`);
30
+ console.log(`Price: $${this.price}`);
31
+ console.log(`Stock: ${this.stock}`);
32
+ }
33
+
34
+ // Check if product is in stock
35
+ isInStock(amountSold: number): boolean {
36
+ return this.stock >= amountSold;
37
+ }
38
+ }
39
+
40
+ class RetailStore {
41
+ private products: Product[] = [];
42
+ private totalRevenue: number = 0;
43
+
44
+ // Method to add a new product to the store
45
+ addProduct(product: Product): void {
46
+ this.products.push(product);
47
+ console.log(`${product.name} added to the store.`);
48
+ }
49
+
50
+ // Method to display all products in the store
51
+ displayProducts(): void {
52
+ if (this.products.length === 0) {
53
+ console.log("No products available.");
54
+ } else {
55
+ console.log("\n--- Available Products ---");
56
+ this.products.forEach((product) => product.displayProduct());
57
+ }
58
+ }
59
+
60
+ // Method to process a sale
61
+ processSale(productId: string, quantity: number): void {
62
+ const product = this.products.find((p) => p.productId === productId);
63
+ if (product) {
64
+ if (product.isInStock(quantity)) {
65
+ product.updateStock(quantity);
66
+ const saleAmount = product.price * quantity;
67
+ this.totalRevenue += saleAmount;
68
+ console.log(`Sale processed: ${quantity} x ${product.name}. Total Sale: $${saleAmount}`);
69
+ } else {
70
+ console.log(`${product.name}: Not enough stock to sell ${quantity} items.`);
71
+ }
72
+ } else {
73
+ console.log("Product not found.");
74
+ }
75
+ }
76
+
77
+ // Method to generate sales report
78
+ generateSalesReport(): void {
79
+ console.log(`\n--- Sales Report ---`);
80
+ console.log(`Total Revenue: $${this.totalRevenue}`);
81
+ }
82
+ }
83
+
84
+ // Main.ts
85
+
86
+ // Initialize the Retail Store
87
+ const store = new RetailStore();
88
+
89
+ // Create products
90
+ const product1 = new Product("P001", "Laptop", 1000, 50);
91
+ const product2 = new Product("P002", "Smartphone", 700, 100);
92
+ const product3 = new Product("P003", "Headphones", 150, 200);
93
+
94
+ // Add products to the store
95
+ store.addProduct(product1);
96
+ store.addProduct(product2);
97
+ store.addProduct(product3);
98
+
99
+ // Display all products in the store
100
+ store.displayProducts();
101
+
102
+ // Process sales
103
+ store.processSale("P001", 5); // Selling 5 Laptops
104
+ store.processSale("P002", 3); // Selling 3 Smartphones
105
+
106
+ // Display updated product details
107
+ store.displayProducts();
108
+
109
+ // Generate sales report
110
+ store.generateSalesReport();
111
+
112
+ // Attempting to sell more than available stock
113
+ store.processSale("P003", 250); // Selling 250 Headphones (more than stock)