Compare commits
13 Commits
zaglooshka
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fb5ebfa422 | |||
| 422b8caef5 | |||
| 07a11d411b | |||
| ff14987c92 | |||
| faef16090f | |||
| 774e96dcbf | |||
| 8c4a82720f | |||
| 262ed144da | |||
| 47744c8389 | |||
| 16f139039d | |||
| 3ae2d6f6ac | |||
| 487790555b | |||
| 01c4104b25 |
7
comparison.py
Normal file
7
comparison.py
Normal file
@ -0,0 +1,7 @@
|
||||
def compare(a: str) -> bool:
|
||||
for i in range(len(a)):
|
||||
if(a[i].isdigit() == False):
|
||||
if a[i] == "<":
|
||||
return int(a[:i]) < int(a[i + 1:])
|
||||
elif (a[i] == ">"):
|
||||
return int(a[:i]) > int(a[i + 1:])
|
||||
4
count_sum_pandas.py
Normal file
4
count_sum_pandas.py
Normal file
@ -0,0 +1,4 @@
|
||||
import pandas as pd
|
||||
|
||||
def count_sum(df: pd.DataFrame) -> pd.DataFrame:
|
||||
return df.groupby('Товар')['Количество'].sum().reset_index().set_index('Товар')
|
||||
12
last_friday_datetime.py
Normal file
12
last_friday_datetime.py
Normal file
@ -0,0 +1,12 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def get_last_friday(a: str) -> str:
|
||||
date = datetime.strptime(a, "%m/%Y").date()
|
||||
next_month = date.replace(day=28) + timedelta(days=7)
|
||||
last_day = next_month - timedelta(days=next_month.day)
|
||||
|
||||
# Идем назад до пятницы
|
||||
while last_day.weekday() != 4:
|
||||
last_day -= timedelta(days=1)
|
||||
|
||||
return last_day.strftime("%d.%m.%Y")
|
||||
20
pom.xml
20
pom.xml
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.18</version> <!-- Стабильная версия для Java 8 -->
|
||||
</parent>
|
||||
|
||||
<groupId>org.lanit</groupId>
|
||||
<artifactId>json-stub</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,11 +0,0 @@
|
||||
package org.lanit;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
package org.lanit.controllers;
|
||||
|
||||
import org.lanit.models.*;
|
||||
import org.lanit.service.JsonProcessingService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
@Controller
|
||||
public class JSONController {
|
||||
|
||||
private final JsonProcessingService processingService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public JSONController(JsonProcessingService processingService, ObjectMapper objectMapper) {
|
||||
this.processingService = processingService;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
|
||||
//Метод для создания JSON ответов с чистым Content-Type
|
||||
|
||||
private ResponseEntity<Object> createJsonResponse(Object body, HttpStatus status) {
|
||||
return ResponseEntity.status(status)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Основной endpoint для обработки JSON запросов
|
||||
* @ResponseBody указывает, что возвращаемое значение должно быть записано в тело ответа
|
||||
*/
|
||||
@PostMapping(value = "/json", produces = "application/json", consumes = "application/json")
|
||||
@ResponseBody
|
||||
public ResponseEntity<?> handleJsonRequest(
|
||||
@RequestParam("action") String action,
|
||||
@RequestBody String jsonBody) throws IOException {
|
||||
|
||||
try {
|
||||
// Обработка действий ADD и DELETE
|
||||
if ("add".equals(action)) {
|
||||
AddRequest addRequest = objectMapper.readValue(jsonBody, AddRequest.class);
|
||||
Info modifiedInfo = processingService.processAdd(addRequest);
|
||||
|
||||
Response response = new Response();
|
||||
response.setInfo(modifiedInfo);
|
||||
response.setUuid(addRequest.getUuid()); // Сохраняем исходный UUID
|
||||
response.setLastUpdate(Instant.now().toString()); // Обновляем время ответа
|
||||
return createJsonResponse(response, HttpStatus.OK);
|
||||
|
||||
} else if ("delete".equals(action)) {
|
||||
DeleteRequest deleteRequest = objectMapper.readValue(jsonBody, DeleteRequest.class);
|
||||
Info modifiedInfo = processingService.processDelete(deleteRequest);
|
||||
|
||||
Response response = new Response();
|
||||
response.setInfo(modifiedInfo);
|
||||
response.setUuid(deleteRequest.getUuid());
|
||||
response.setLastUpdate(Instant.now().toString());
|
||||
return createJsonResponse(response, HttpStatus.OK);
|
||||
|
||||
} else {
|
||||
// Обработка неизвестных действий
|
||||
ErrorResponse error = new ErrorResponse();
|
||||
error.setStatus("error");
|
||||
error.setMessage("Передан некорректный action - " + action);
|
||||
return createJsonResponse(error, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
ErrorResponse error = new ErrorResponse();
|
||||
error.setStatus("error");
|
||||
error.setMessage(e.getMessage());
|
||||
// Определяем HTTP статус на основе текста ошибки
|
||||
HttpStatus status = e.getMessage().contains("тикер") || e.getMessage().contains("индекс")
|
||||
? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST;
|
||||
return createJsonResponse(error, status);
|
||||
|
||||
} catch (IOException e) {
|
||||
// Обработка ошибок парсинга JSON
|
||||
ErrorResponse error = new ErrorResponse();
|
||||
error.setStatus("error");
|
||||
error.setMessage("Ошибка разбора JSON");
|
||||
return createJsonResponse(error, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Add {
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("timeFrame")
|
||||
private int timeFrame;
|
||||
|
||||
@JsonProperty("percent")
|
||||
private int percent;
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public int getTimeFrame() { return timeFrame; }
|
||||
public void setTimeFrame(int timeFrame) { this.timeFrame = timeFrame; }
|
||||
public int getPercent() { return percent; }
|
||||
public void setPercent(int percent) { this.percent = percent; }
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class AddRequest {
|
||||
@JsonProperty("info")
|
||||
private Info info;
|
||||
|
||||
@JsonProperty("add")
|
||||
private Add add;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private String uuid;
|
||||
|
||||
@JsonProperty("lastUpdate")
|
||||
private String lastUpdate;
|
||||
|
||||
public Info getInfo() { return info; }
|
||||
public void setInfo(Info info) { this.info = info; }
|
||||
public Add getAdd() { return add; }
|
||||
public void setAdd(Add add) { this.add = add; }
|
||||
public String getUuid() { return uuid; }
|
||||
public void setUuid(String uuid) { this.uuid = uuid; }
|
||||
public String getLastUpdate() { return lastUpdate; }
|
||||
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Alert {
|
||||
@JsonProperty("timeFrame")
|
||||
private int timeFrame;
|
||||
|
||||
@JsonProperty("percent")
|
||||
private int percent;
|
||||
|
||||
public int getTimeFrame() { return timeFrame; }
|
||||
public void setTimeFrame(int timeFrame) { this.timeFrame = timeFrame; }
|
||||
public int getPercent() { return percent; }
|
||||
public void setPercent(int percent) { this.percent = percent; }
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Delete {
|
||||
@JsonProperty("tickerName")
|
||||
private String tickerName;
|
||||
|
||||
@JsonProperty("alertIndex")
|
||||
private int alertIndex;
|
||||
|
||||
public String getTickerName() { return tickerName; }
|
||||
public void setTickerName(String tickerName) { this.tickerName = tickerName; }
|
||||
public int getAlertIndex() { return alertIndex; }
|
||||
public void setAlertIndex(int alertIndex) { this.alertIndex = alertIndex; }
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class DeleteRequest {
|
||||
@JsonProperty("info")
|
||||
private Info info;
|
||||
|
||||
@JsonProperty("delete")
|
||||
private Delete delete;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private String uuid;
|
||||
|
||||
@JsonProperty("lastUpdate")
|
||||
private String lastUpdate;
|
||||
|
||||
public Info getInfo() { return info; }
|
||||
public void setInfo(Info info) { this.info = info; }
|
||||
public Delete getDelete() { return delete; }
|
||||
public void setDelete(Delete delete) { this.delete = delete; }
|
||||
public String getUuid() { return uuid; }
|
||||
public void setUuid(String uuid) { this.uuid = uuid; }
|
||||
public String getLastUpdate() { return lastUpdate; }
|
||||
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class ErrorResponse {
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public String getMessage() { return message; }
|
||||
public void setMessage(String message) { this.message = message; }
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
public class Info {
|
||||
@JsonProperty("userID")
|
||||
private String userID;
|
||||
|
||||
@JsonProperty("tickers")
|
||||
private List<Ticker> tickers;
|
||||
|
||||
public String getUserID() { return userID; }
|
||||
public void setUserID(String userID) { this.userID = userID; }
|
||||
public List<Ticker> getTickers() { return tickers; }
|
||||
public void setTickers(List<Ticker> tickers) { this.tickers = tickers; }
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Response {
|
||||
@JsonProperty("info")
|
||||
private Info info;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private String uuid;
|
||||
|
||||
@JsonProperty("lastUpdate")
|
||||
private String lastUpdate;
|
||||
|
||||
public Info getInfo() { return info; }
|
||||
public void setInfo(Info info) { this.info = info; }
|
||||
public String getUuid() { return uuid; }
|
||||
public void setUuid(String uuid) { this.uuid = uuid; }
|
||||
public String getLastUpdate() { return lastUpdate; }
|
||||
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package org.lanit.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
public class Ticker {
|
||||
@JsonProperty("ticker")
|
||||
private String ticker;
|
||||
|
||||
@JsonProperty("alerts")
|
||||
private List<Alert> alerts;
|
||||
|
||||
public String getTicker() { return ticker; }
|
||||
public void setTicker(String ticker) { this.ticker = ticker; }
|
||||
public List<Alert> getAlerts() { return alerts; }
|
||||
public void setAlerts(List<Alert> alerts) { this.alerts = alerts; }
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
package org.lanit.service;
|
||||
|
||||
import org.lanit.models.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class JsonProcessingService {
|
||||
|
||||
public Info processAdd(AddRequest request) {
|
||||
Info info = request.getInfo();
|
||||
Add add = request.getAdd();
|
||||
List<Ticker> tickers = info.getTickers();
|
||||
|
||||
// Ищем тикер
|
||||
Optional<Ticker> existingTicker = tickers.stream()
|
||||
.filter(t -> t.getTicker().equals(add.getName()))
|
||||
.findFirst();
|
||||
|
||||
Ticker targetTicker;
|
||||
if (existingTicker.isPresent()) {
|
||||
targetTicker = existingTicker.get();
|
||||
} else {
|
||||
// Создаем новый тикер
|
||||
targetTicker = new Ticker();
|
||||
targetTicker.setTicker(add.getName());
|
||||
targetTicker.setAlerts(new java.util.ArrayList<>());
|
||||
tickers.add(targetTicker);
|
||||
}
|
||||
|
||||
// Создаем и добавляем оповещение
|
||||
Alert newAlert = new Alert();
|
||||
newAlert.setTimeFrame(add.getTimeFrame());
|
||||
newAlert.setPercent(add.getPercent());
|
||||
targetTicker.getAlerts().add(newAlert);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public Info processDelete(DeleteRequest request) {
|
||||
Info info = request.getInfo();
|
||||
Delete delete = request.getDelete();
|
||||
List<Ticker> tickers = info.getTickers();
|
||||
|
||||
// Ищем тикер
|
||||
Ticker targetTicker = tickers.stream()
|
||||
.filter(t -> t.getTicker().equals(delete.getTickerName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Передан некорректный тикер"));
|
||||
|
||||
// Проверяем индекс
|
||||
List<Alert> alerts = targetTicker.getAlerts();
|
||||
int index = delete.getAlertIndex();
|
||||
if (index < 0 || index >= alerts.size()) {
|
||||
throw new RuntimeException("Передан некорректный индекс");
|
||||
}
|
||||
|
||||
// Удаляем оповещение
|
||||
alerts.remove(index);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
8
src/main/resources/sql-extended.properties
Normal file
8
src/main/resources/sql-extended.properties
Normal file
@ -0,0 +1,8 @@
|
||||
task1=SELECT COUNT(*) AS total_boarding_passes FROM boarding_passes;
|
||||
task2=SELECT COUNT(DISTINCT ticket_no) AS unique_passengers_count FROM boarding_passes WHERE seat_no = '17E';
|
||||
task3=SELECT MAX(amount) AS most_expensive_ticket, MIN(amount) AS cheapest_ticket, AVG(amount) AS average_ticket_price FROM ticket_flights;
|
||||
task4=SELECT passenger_name FROM tickets WHERE passenger_id LIKE '8099%43' AND book_ref LIKE 'B%';
|
||||
task5=SELECT COUNT(*) AS flights_count FROM flights WHERE aircraft_code IN (SELECT aircraft_code FROM aircrafts_data WHERE model LIKE '%Cessna 208 Caravan%');
|
||||
task6=SELECT ad.airport_name, ad.city, f.flight_id, f.flight_no FROM flights f JOIN airports_data ad ON f.departure_airport = ad.airport_code WHERE f.flight_no = 'PG0305' AND f.scheduled_departure = '2017-09-09 09:10:00+04';
|
||||
task7=SELECT a.model FROM flights f JOIN aircrafts_data a ON f.aircraft_code = a.aircraft_code WHERE f.flight_no = 'PG0210' LIMIT 1;
|
||||
task8=SELECT passenger_name AS FI FROM tickets WHERE passenger_name ILIKE '% anna %' OR passenger_name ILIKE 'anna %' OR passenger_name ILIKE '% anna' UNION SELECT CONCAT(first_name, ' ', last_name) AS FI FROM employees WHERE first_name ILIKE '%anna%' OR last_name ILIKE '%anna%';
|
||||
Loading…
Reference in New Issue
Block a user